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

Discussion in 'Perl Misc' started by Guy, Dec 7, 2003.

  1. Guy

    Guy Guest

    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
     
    Guy, Dec 7, 2003
    #1
    1. Advertising

  2. Re: Do we just use different file handles when we want to havemultiple files open at the same time...?

    On Sun, 07 Dec 2003 17:15:32 GMT
    "Guy" <> 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."
     
    James Willmore, Dec 7, 2003
    #2
    1. Advertising

  3. Guy

    Erik Tank Guest

    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" <>
    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
    >
     
    Erik Tank, Dec 7, 2003
    #3
  4. Guy

    Matt Garrish Guest

    "James Willmore" <> wrote in message
    news:...
    > On Sun, 07 Dec 2003 17:15:32 GMT
    > "Guy" <> 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
     
    Matt Garrish, Dec 8, 2003
    #4
  5. Guy

    Sara Guest

    "Matt Garrish" <> wrote in message news:<6TTAb.6796$>...
    > "James Willmore" <> wrote in message
    > news:...
    > > On Sun, 07 Dec 2003 17:15:32 GMT
    > > "Guy" <> 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
     
    Sara, Dec 8, 2003
    #5
  6. Guy

    Matt Garrish Guest

    "Sara" <> wrote in message
    news:...
    > "Matt Garrish" <> wrote in message

    news:<6TTAb.6796$>...
    > > "James Willmore" <> wrote in message
    > > news:...
    > > >
    > > > 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
     
    Matt Garrish, Dec 8, 2003
    #6
  7. Re: Do we just use different file handles when we want to havemultiple files open at the same time...?

    On Mon, 8 Dec 2003 00:21:09 -0500
    "Matt Garrish" <> 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
     
    James Willmore, Dec 8, 2003
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?bGFuZW0=?=
    Replies:
    3
    Views:
    4,294
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
    Feb 22, 2006
  2. eino
    Replies:
    1
    Views:
    455
    =?ISO-8859-15?Q?=22Martin_v=2E_L=F6wis=22?=
    May 8, 2007
  3. Christopher Brewster
    Replies:
    5
    Views:
    374
    John Machin
    Nov 14, 2008
  4. bluebaron
    Replies:
    3
    Views:
    787
    Jonathan N. Little
    Nov 4, 2009
  5. Guest
    Replies:
    2
    Views:
    201
    Foo Man Chew
    Dec 29, 2003
Loading...

Share This Page