T
Tassilo v. Parseval
Also sprach Michele Dondi:
I think it's pretty safe to expect that. select() will increment the
reference-count of its argument and decrement the ref-count of the
previous default handle when a new handle is selected.
I am pretty sure that the porters wont change that in future.
Tassilo
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?
I think it's pretty safe to expect that. select() will increment the
reference-count of its argument and decrement the ref-count of the
previous default handle when a new handle is selected.
I am pretty sure that the porters wont change that in future.
Tassilo