Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Re^3: Iterator to parse multiline string with \\n terminator

by Laurent_R (Abbot)
on Oct 06, 2013 at 09:29 UTC ( #1057136=note: print w/replies, xml ) Need Help??

in reply to Re^2: Iterator to parse multiline string with \\n terminator
in thread Iterator to parse multiline string with \\n terminator

$fh is a file handler, i.e. it is actually an iterator on a file, so that each time you read from $fh, you get the next line. In your sub, your my $fh = shift; actually creates a new copy of $fh each time the sub is called. It still works because $fh "knows" which is the next line to read from the file. But your anonymous sub is not a closure; the alternative code I wrote is actually keeping its own copy of $fh, my anonymous sub actually closes on $fh. Please note that an anonymous function is not necessarily a closure, and a closure does not necessarily have to be anonymous (although is is often the case).

You might want to have a look to this: Closure on Closures.

Replies are listed 'Best First'.
Re^4: Iterator to parse multiline string with \\n terminator
by three18ti (Scribe) on Oct 06, 2013 at 10:57 UTC
    Awesome! Thanks for the info and link.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1057136]
[Corion]: Ruining other peoples clones is not nice, but as I only have that repo to (later) show people when I encounter problems, I don't mind that
[Corion]: I should look into self-hosting gitprep instead of relying so much on github

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (8)
As of 2017-01-23 10:35 GMT
Find Nodes?
    Voting Booth?
    Do you watch meteor showers?

    Results (192 votes). Check out past polls.