A few days ago I was about to answer a post in which a user asked for
advice on creating per-directory reports with File::Find.
Amongst the possible solutions that came to my mind, I though of using
something like this (tested!):
#!/usr/bin/perl -l
# Oversimplified example
use strict;
use warnings;
use File::Find;
File::Find::find { preprocess => sub {
open my $fh, '>', '_report.txt' or
die "Can't open `$File::Find::dir/_report.txt': $!\n";
select $fh;
@_ },
wanted => sub {
print;
}
}, @ARGV;
__END__
Eventually, I didn't post it for (i) it was probably too late, and
good answers had already been given to the OP, (ii) I was not 100%
sure about this approach.
Now my question is if there are possible issues with select()ing a
lexical filehandle: it is my understanding that it won't cease to
exist till references to it exists too, and select() seems to do just
this, keeping it in life, but is this guaranteed to continue working
in future releases of perl?
Please note that even if I can't imagine situations in which this
could be useful, but that described above, my question is *not* about
File::Find.
Michele
--
# This prints: Just another Perl hacker,
seek DATA,15,0 and print q... <DATA>;
__END__
|