in reply to need nextline() sub
Now we have a fly-weight object (tilly's words I think) which will return the next line from the filehandle you initially provided to nextline(). There's loads of info about closures around the Monastery that are well worth the read if you're unsure about them (although having read a bunch of stuff on closures I only clicked recently having read tye's node on Finding all Combinations). You can also do funky stuff like grokking the symbol table and dynamically creating subs, but I think that's better left to a later node.use strict; sub nextline { my $fh = shift; return sub { return scalar <$fh>; } } open(FOO, "somefile.txt") or die("Doh - $!"); my $nl = nextline(*FOO{IO}); print $nl->() for 0..3; close(FOO); __END__ =INPUT foo bar baz quux xxx yy z =OUTPUT foo bar baz quux
broquaint
|
|---|