On 12/10/2012 04:39 PM, Rich Johnson wrote:
I am working my way through Intermediate Perl and have a question
concerning one of the exercises (It's a long-ish exercise, so I won't
bother typing it out as it's irrelevant to the question at hand). The
author's solution contains the following code:
... code ...
my ($gather, $yield) = gather_mtime_between($start, $stop);
find($gather, @starting_directories);
my @files = yield->();
... more code ...
sub gather_mtime_between{
my ($begin, $end) = @_;
my @files;
my $gatherer = sub {
* my $timestamp (stat $_)[9]*
unless (defined $timestamp) {
warn "...";
return;
}
...
};
...
}
My question is about the bold: Where is $_ getting its value?
first off, did you type that code in by hand? there is no = in the line
you marked with **.
you need to read the docs on the File::Find module. it does a callback
to a sub (in this case the code ref assigned to $gather from
gather_mtime_between). before it does each callback find() sets $_ to
the file it just found. there are other things set globally by find
which can be very useful so learn more about that module.
uri
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/