K
Krishna Chaitanya
Hi,
Following's an extract from Perl FAQ 7.13 (closures):
****************
Closures are often used for less esoteric purposes. For example,
when
you want to pass in a bit of code into a function:
my $line;
timeout( 30, sub { $line = <STDIN> } );
If the code to execute had been passed in as a string, '$line =
<STDIN>', there would have been no way for the hypothetical
timeout()
function to access the lexical variable $line back in its
caller's
scope.
****************
I'm not clear about what's being said here...why would timeout need to
access $line here at all? What would be wrong with:
timeout(30,scalar(<STDIN>));
What's the real, "less esoteric", use of the closure being described
here? Pls. help me...am I missing something obvious?
Thanks in advance,
Chaitanya
P.S: Pardon me if this is something silly which's escaping me...am
overworked. Pls. bear...
Following's an extract from Perl FAQ 7.13 (closures):
****************
Closures are often used for less esoteric purposes. For example,
when
you want to pass in a bit of code into a function:
my $line;
timeout( 30, sub { $line = <STDIN> } );
If the code to execute had been passed in as a string, '$line =
<STDIN>', there would have been no way for the hypothetical
timeout()
function to access the lexical variable $line back in its
caller's
scope.
****************
I'm not clear about what's being said here...why would timeout need to
access $line here at all? What would be wrong with:
timeout(30,scalar(<STDIN>));
What's the real, "less esoteric", use of the closure being described
here? Pls. help me...am I missing something obvious?
Thanks in advance,
Chaitanya
P.S: Pardon me if this is something silly which's escaping me...am
overworked. Pls. bear...