Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Re: How To: Make An Iterator

by kelan (Deacon)
on Apr 25, 2005 at 21:13 UTC ( #451349=note: print w/ replies, xml ) Need Help??

in reply to How To: Make An Iterator

Here's another take on the first example that only returns one line at a time until all filehandles are exhausted and returns undef when that happens.

sub gen_fh_iterator { my ( $current, @fhs ) = @_; return sub { my $line; while ( ! defined $line && @fhs ) { $line = <$current>; $current = shift @fhs if not defined $line; } return $line; }; } my $file_iter = gen_fh_iterator( @fhs ); while ( my $line = $file_iter->() ) { print "$line\n"; }

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

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (4)
As of 2015-11-28 21:36 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (745 votes), past polls