Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Opening multiple files simultaneously

by kyle (Abbot)
on Mar 31, 2009 at 14:36 UTC ( #754438=note: print w/replies, xml ) Need Help??


in reply to Opening multiple files simultaneously

The "open $scalar" idiom takes an undefined scalar and gives it a value. That value is a particular filehandle. If you then open the same filehandle again, it closes the old file.

Try this.

sub open_new { my ( $filename ) = @_; open my $fh, '<', $filename or die "Can't read '$filename': $!"; return $fh; } push @filestack, open_new( 'test1.txt' ); push @filestack, open_new( 'test2.txt' );

Inside open_new, there's a new $fh containing undef every time.

Replies are listed 'Best First'.
Re^2: Opening multiple files simultaneously
by chrishowe (Acolyte) on Mar 31, 2009 at 15:42 UTC
    Superb, cheers :-)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://754438]
help
Chatterbox?
[Discipulus]: yes I know, bro' and I also know I cannot compete. But no one ask for oneliners.. ;=)
[Discipulus]: and i'm just happy for rising the black camel in the main ladderboard

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (6)
As of 2017-10-22 20:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My fridge is mostly full of:

















    Results (275 votes). Check out past polls.

    Notices?