Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Do we just use different file handles when we want to have multiple files open at the same time...?

Reply
Thread Tools

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

 
 
Guy
Guest
Posts: n/a
 
      12-07-2003
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


 
Reply With Quote
 
 
 
 
James Willmore
Guest
Posts: n/a
 
      12-07-2003
On Sun, 07 Dec 2003 17:15:32 GMT
"Guy" <(E-Mail Removed)> wrote:

> 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."
 
Reply With Quote
 
 
 
 
Erik Tank
Guest
Posts: n/a
 
      12-07-2003
That is pretty much all you have to do to open multiple files at the
same time.

On Sun, 07 Dec 2003 17:15:32 GMT, "Guy" <(E-Mail Removed)>
wrote:

>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
>


 
Reply With Quote
 
Matt Garrish
Guest
Posts: n/a
 
      12-08-2003

"James Willmore" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) phia.net...
> On Sun, 07 Dec 2003 17:15:32 GMT
> "Guy" <(E-Mail Removed)> wrote:
>
> > 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";
>


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


 
Reply With Quote
 
Sara
Guest
Posts: n/a
 
      12-08-2003
"Matt Garrish" <(E-Mail Removed)> wrote in message news:<6TTAb.6796$(E-Mail Removed)> ...
> "James Willmore" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed) phia.net...
> > On Sun, 07 Dec 2003 17:15:32 GMT
> > "Guy" <(E-Mail Removed)> wrote:
> >
> > > 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";
> >

>
> 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
 
Reply With Quote
 
Matt Garrish
Guest
Posts: n/a
 
      12-08-2003

"Sara" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> "Matt Garrish" <(E-Mail Removed)> wrote in message

news:<6TTAb.6796$(E-Mail Removed)> ...
> > "James Willmore" <(E-Mail Removed)> wrote in message
> > news:(E-Mail Removed) phia.net...
> > >
> > > 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";

>
> 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


 
Reply With Quote
 
James Willmore
Guest
Posts: n/a
 
      12-08-2003
On Mon, 8 Dec 2003 00:21:09 -0500
"Matt Garrish" <(E-Mail Removed)> wrote:
> 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

 
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
Weird issue, same code, same browser, two different apache servers,very different css bluebaron HTML 3 11-04-2009 07:13 PM
running same script on same data on two different machines -->different result Christopher Brewster Python 5 11-14-2008 08:19 PM
Re: how to open a file in some application using Tkinter i am usingTKINTER to create GUI application i want to know how to open a worddocument in open office or any other applicatio Fredrik Lundh Python 1 01-09-2008 10:40 AM
Question about file handles and windows handles @ Windows Operating Systems eino Python 1 05-08-2007 09:14 PM
same code produces different decimal symbol on different computers with same settings ASP General 2 12-29-2003 02:29 PM



Advertisments