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

How To: Make An Iterator

by Limbic~Region (Chancellor)
on Apr 25, 2005 at 17:20 UTC ( #451278=perltutorial: print w/ replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    sub gen_iterator {
        my @initial_info = @_;
    ...
            return $current_state = $next_state;   
        };
    }
    
  2. or download this
    my $next = gen_iterator( 42 );
    while ( my $item = $next->() ) {
        print "$item\n";
    }
    
  3. or download this
    my @DNA = qw/A C T G/;
    my $seq = gen_permutate(14, @DNA);
    ...
            return join '', map { $list[ $_ ] } @curr;
        };
    }
    
  4. or download this
    my $start = $ARGV[0] || 999999;
    my $next_id = gen_id( $start );
    ...
        $tot += $_ for split //, $chk;
        return $tot % 10 == 0 ? 1 : 0;
    }
    
  5. or download this
    my $next_file = rotate( qw/FileA FileB FileC/ );
    print $next_file->(), "\n" for 1 .. 10;
    ...
            return $list[ $index ];
        };
    }
    
  6. or download this
    while ( my $pass = $next_pw->() ) {
        if ( unlock( $pass ) ) {
    ...
        };
    }
    sub unlock { $_[0] eq 'john' }
    
  7. or download this
    my @list = map { my @lines = <$_>; \@lines } @f_handles;
    # becomes
    ...
            return \@lines;
        };
    }
    
  8. or download this
    sub infinite_evens {
        my $curr = shift;
    ...
    }
    my $next_even = infinite_evens( 41 );
    print $next_even->(), "\n" while 1;
    

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (10)
As of 2014-12-21 16:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (106 votes), past polls