On Sun, 26 Aug 2007 13:04:48 -0400, Mr. Shawn H. Corey wrote:
> I have worked in programming for 25 years and during that time I have
> never use a closure and have never seen one used.
Boggle. I don't think any program I write these days doesn't have one.
They're the most convenient way of restricting static variable scope.
> Dealing with a closure has two phases. A phases when its created
> (compiled phase) and one when it's executed (run phase). When you write a
> closure you have to keep the two phases in mind (and separate).
Ah, I think the problem is your definition of 'closure'. I believe
you're confining it to the function factory:
sub incr { my $x = shift; return sub { $x++ } }
In fact this is also a closure:
{ # Naked block
my $fh; # Scoped to this block
sub write_log {
open $fh, '>', $LOGFILE or die $! unless $fh;
print $fh @_;
}
}
write_log() is closed on $fh.
--
Peter Scott
http://www.perlmedic.com/
http://www.perldebugged.com/
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/