in reply to Re: Closures and callbacks...
in thread Closures and callbacks...
I'd like to point out that these aren't really closures...The read_row function is a closure, it just happens to be a non-encapsulated closure as process can also see @indexes. It would act as a more effective closure if it was re-structured like so
use Symbol; { my @indexes = qw (3 0 4 5 6 7); my $fh = gensym; open $fh,"<my.dat" or die "my.dat: $!"; sub read_row { my $row = <$fh>; close $fh and return unless defined($row); return (split(/\s+/,$row))[@indexes]; } }
_________
broquaint
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: Closures and callbacks...
by zigdon (Deacon) on Oct 23, 2002 at 12:17 UTC | |
by broquaint (Abbot) on Oct 23, 2002 at 12:37 UTC |