restarting <> (stdio)

Discussion in 'Perl Misc' started by J, Feb 16, 2004.

  1. J

    J Guest

    I'm still learning Perl, so i'm sorry if I get the lingo completely wrong.

    I have a script that take a filename as an arguement. I process each line of
    the file using the while( <> ) statement. That works perfectly.

    However, now I need to start at the beginning of the input file. I can't
    figure out how to do this to save my life. Any suggestions?

    J
     
    J, Feb 16, 2004
    #1
    1. Advertising

  2. J

    J Guest

    On Mon, 16 Feb 2004 1:01:23 -0500, Klaas wrote
    (in message <Xns9490E05FC9A72nothing@209.98.50.131>):

    > After careful consideration, J muttered:
    >
    >> I'm still learning Perl, so i'm sorry if I get the lingo completely
    >> wrong.
    >>
    >> I have a script that take a filename as an arguement. I process each
    >> line of the file using the while( <> ) statement. That works
    >> perfectly.
    >>
    >> However, now I need to start at the beginning of the input file. I
    >> can't figure out how to do this to save my life. Any suggestions?

    >
    > Let me preface with 'I am a perl newbie'.
    >
    > If you save @ARGV and reset it after <> returns false, the next time <> is
    > encountered it will re-process @ARGV.
    >
    > -Mike


    thank you so much. That worked perfectly.

    J
     
    J, Feb 16, 2004
    #2
    1. Advertising

  3. In article <>,
    J <> wrote:
    >I'm still learning Perl, so i'm sorry if I get the lingo completely wrong.
    >
    >I have a script that take a filename as an arguement. I process each line of
    >the file using the while( <> ) statement. That works perfectly.
    >
    >However, now I need to start at the beginning of the input file. I can't
    >figure out how to do this to save my life. Any suggestions?
    >


    If you're talking about re-reading the file with <>,
    something like this perhaps:

    my $arg = $ARGV[0];
    while ( <> ) {
    ...
    }
    ....
    $ARGV[0] = $arg;
    while ( <>) {
    ....

    check perlop for details about ARGV and friends...

    hth,
    --
    Charles DeRykus
     
    Charles DeRykus, Feb 16, 2004
    #3
    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. Robert Maas, see http://tinyurl.com/uh3t

    How to disable stdio echoplex from java code (unix specific)?

    Robert Maas, see http://tinyurl.com/uh3t, Jun 7, 2005, in forum: Java
    Replies:
    0
    Views:
    397
    Robert Maas, see http://tinyurl.com/uh3t
    Jun 7, 2005
  2. Vicent

    iostream or stdio

    Vicent, Aug 25, 2003, in forum: C++
    Replies:
    2
    Views:
    1,733
  3. paul calvert
    Replies:
    6
    Views:
    2,162
  4. fang
    Replies:
    1
    Views:
    576
    Victor Bazarov
    Apr 13, 2005
  5. Replies:
    18
    Views:
    1,913
    crazzybugger
    Oct 22, 2006
Loading...

Share This Page