Do we just use different file handles when we want to have multiple files open at the same time...?

G

Guy

To have many files open at the same time, do I just use a different file
handle like this:

open(FILEA,"$stopfil");
open(FILEB,"$startfil");

# some extra code goes here

close(FILEA);
close(FILEB);

Or are there other things that have to be done also.

Guy Doucet
 
J

James Willmore

To have many files open at the same time, do I just use a different
file handle like this:

open(FILEA,"$stopfil");
open(FILEB,"$startfil");

# some extra code goes here

close(FILEA);
close(FILEB);

Or are there other things that have to be done also.

That will work. However, I'd check to see if you actually opened the
file.

open(FILEA,"$stopfil") or die "Open failed for $stopfil: $!\n";
open(FILEB,"$startfil") or die "Open failed for $starfil: $!\n";

HTH

--
Jim

Copyright notice: all code written by the author in this post is
released under the GPL. http://www.gnu.org/licenses/gpl.txt
for more information.

a fortune quote ...
"Do not meddle in the affairs of wizards, for you are crunchy and
good with ketchup."
 
E

Erik Tank

That is pretty much all you have to do to open multiple files at the
same time.
 
M

Matt Garrish

James Willmore said:
That will work. However, I'd check to see if you actually opened the
file.

open(FILEA,"$stopfil") or die "Open failed for $stopfil: $!\n";
open(FILEB,"$startfil") or die "Open failed for $starfil: $!\n";

I'd also drop the useless quotes:

open(FILEA, $stopfil) or die "Open failed for $stopfil: $!\n";
open(FILEB, $startfil) or die "Open failed for $starfil: $!\n";

Matt
 
S

Sara

Matt Garrish said:
I'd also drop the useless quotes:

open(FILEA, $stopfil) or die "Open failed for $stopfil: $!\n";
open(FILEB, $startfil) or die "Open failed for $starfil: $!\n";

Matt

might as well clean things up a little more while were at it..

die "Why me?\n\n" unless ( open FILEA, $stopfil ) && open FILEB, $startfil;

G
 
M

Matt Garrish

Sara said:
"Matt Garrish" <[email protected]> wrote in message

might as well clean things up a little more while were at it..

die "Why me?\n\n" unless ( open FILEA, $stopfil ) && open FILEB, $startfil;

That's clean? You aren't getting the error message if it fails, and even if
you were how would you know which open it applied to? I personally prefer
James' method, where the file and error message are clearly identified. Why
add to your debugging time just to save a line?

Matt
 
J

James Willmore

I'd also drop the useless quotes:

open(FILEA, $stopfil) or die "Open failed for $stopfil: $!\n";
open(FILEB, $startfil) or die "Open failed for $starfil: $!\n";

True. See what I get fro re-typing code :)

--
Jim

Copyright notice: all code written by the author in this post is
released under the GPL. http://www.gnu.org/licenses/gpl.txt
for more information.

a fortune quote ...
%DCL-MEM-BAD, bad memory VMS-F-PDGERS, pudding between the ears
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top