10 PRINT "ERIK" 20 GOTO 10
Archives
You are currently viewing archive for April 2009
30/04:
iterators in perl using unix pipes.
Category:
perl
Posted by:
erik
Add comment
sub
yieldfor
(
&
\
&
)
{
if
(
open
(
TO
,
"-|"
)
)
{
while
(
<TO>
)
{
&
{
$_
[
0
]
}
;
}
close
(
TO
)
;
}
else
{
&
{
$_
[
1
]
}
;
}
}
sub
yield
(
$)
{
print
"$_[0]
\n
"
;
}
example usage
sub
fib
(
)
{
my
(
$a
,
$b
)
=
(
0
,
1
)
;
while
(
1
)
{
yield
$b
;
(
$a
,
$b
)
=
(
$b
,
$a
+
$b
)
;
}
}
yieldfor
{
print
;
}
&
fib
;
Sidebar
Navigation
Previous month
Next month
Today
Archives
Categories
All
f#
General
perl
Blogs
10 PRINT "ERIK" 20 GOTO 10
Search
Login
Username:
Password:
Shared Computer