Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: how can i use one handle for multiple files

by hacker (Priest)
on May 15, 2003 at 11:15 UTC ( [id://258358]=note: print w/replies, xml ) Need Help??


in reply to Re: how can i use one handle for multifple files
in thread how can i use one handle for multifple files

The other benefit here, is that scalars can go out of scope, while file handles can't.. which can be very advantageous in some cases, because it provides for automatic cleanup so you don't have to close your filehandles explicitly in subs and blocks.
  • Comment on Re: how can i use one handle for multiple files

Replies are listed 'Best First'.
Re: Re: how can i use one handle for multiple files
by bart (Canon) on May 15, 2003 at 13:04 UTC
    File handles can go out of scope, if you use localized typeglobs.
    { local *FH; open FH, ">output.txt" or die "Can't write to file: $!"; print FH "Anything...\n"; printf STDERR "fileno for FH: %d\n", fileno(FH); } # ... open FH2, ">output2.txt" or die "Can't write to file: $!"; printf STDERR "fileno for FH2: %d\n", fileno(FH2);
    The file handle will be closed when the block is exited. It is extremely likely that you'll see the same value for fileno() for both handles... (for this as a script, I expect to see the value 3) indicating that the first one was released, thus, the handle got closed.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://258358]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (3)
As of 2024-04-19 17:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found