Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: How To: Make An Iterator

by eric256 (Parson)
on Apr 25, 2005 at 22:35 UTC ( #451366=note: print w/ replies, xml ) Need Help??


in reply to How To: Make An Iterator

Hardly original but my own fibonacci number generator.

use strict; use warnings; $| = 1; sub infinite_fib { my ($last,$curr) = @_; return sub { my $temp = $last + $curr; $last = $curr; $curr = $temp; return $curr; }; } my $next_fib = infinite_fib( 1,0 ); print $next_fib->(), "\n" for(1..10);

Kinda fun just because it reaches infinity in a pretty big hurry if you let it run.


___________
Eric Hodges


Comment on Re: How To: Make An Iterator
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://451366]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (9)
As of 2014-07-24 23:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (167 votes), past polls