Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > select()ing a lexical FH

Reply
Thread Tools

select()ing a lexical FH

 
 
Tassilo v. Parseval
Guest
Posts: n/a
 
      12-18-2003
Also sprach Michele Dondi:

> 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
--
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus}) !JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexi ixesixeseg;y~\n~~dddd;eval
 
Reply With Quote
 
 
 
 
Michele Dondi
Guest
Posts: n/a
 
      12-18-2003
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__
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with TransformerHandler and Lexical events Collin VanDyck XML 0 11-30-2004 04:35 PM
Help with lexical events and a TransformerHandler Collin VanDyck Java 0 11-30-2004 03:05 PM
use streamtokenizer to implement lexical analyzer Eric Java 3 12-26-2003 08:28 PM
Python lexical scanner cricket Python 0 09-25-2003 03:58 PM
Lexical convention Ron C++ 0 08-30-2003 08:40 AM



Advertisments