Skipping a file when perl -na is in effect

Discussion in 'Perl Misc' started by bernd, Oct 26, 2006.

  1. bernd

    bernd Guest

    Hello folks,

    does somebody know the proper way of skipping a single input file (or
    at least proceed with the next one) when processing a list of files
    given on the command line when running perl -na, that means, the lines
    of the current file should not be read in (any more) but the program
    should start with the next file in the argument list

    close ARGV ;

    does not work obviuosly, it just resets $.

    An additional

    $ARGV = shift @ARGV ;

    does not help either, since $ARGV contains the name of the next file
    then, but $_ does not change immediately.

    Any idea?

    Cheers


    Bernd
     
    bernd, Oct 26, 2006
    #1
    1. Advertising

  2. bernd

    Paul Lalli Guest

    bernd wrote:
    > does somebody know the proper way of skipping a single input file (or
    > at least proceed with the next one) when processing a list of files
    > given on the command line when running perl -na, that means, the lines
    > of the current file should not be read in (any more) but the program
    > should start with the next file in the argument list
    >
    > close ARGV ;
    >
    > does not work obviuosly, it just resets $.


    I don't know where you're getting "obviously" from, as close ARGV is
    exactly what you need to use.

    $ cat file1.txt
    more stuff
    line 2
    skip all of
    this text
    $ cat file2.txt
    this whole file
    should be
    seen completely.
    $ perl -lne'
    close ARGV and next if /skip/;
    print "($ARGV - $.) $_";
    ' file*.txt
    (file1.txt - 1) more stuff
    (file1.txt - 2) line 2
    (file2.txt - 1) this whole file
    (file2.txt - 2) should be
    (file2.txt - 3) seen completely.


    Paul Lalli
     
    Paul Lalli, Oct 26, 2006
    #2
    1. Advertising

  3. bernd

    Guest

    "bernd" <> wrote:
    > Hello folks,
    >
    > does somebody know the proper way of skipping a single input file (or
    > at least proceed with the next one) when processing a list of files
    > given on the command line when running perl -na, that means, the lines
    > of the current file should not be read in (any more) but the program
    > should start with the next file in the argument list
    >
    > close ARGV ;
    >
    > does not work obviuosly, it just resets $.


    Can you demonstrate it obviously not working? In my hands, it does exactly
    what you want.

    Xho

    --
    -------------------- http://NewsReader.Com/ --------------------
    Usenet Newsgroup Service $9.95/Month 30GB
     
    , Oct 26, 2006
    #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. dm1608
    Replies:
    0
    Views:
    389
    dm1608
    Feb 23, 2006
  2. Ivan Liu
    Replies:
    3
    Views:
    456
    Jerry Coffin
    Sep 5, 2006
  3. MRAB
    Replies:
    3
    Views:
    341
    Lionel
    Feb 5, 2009
  4. Lionel
    Replies:
    2
    Views:
    332
    Slaunger
    Feb 6, 2009
  5. framness

    PERL Skipping a Call to a Sub.

    framness, Aug 14, 2007, in forum: Perl Misc
    Replies:
    6
    Views:
    90
    framness
    Aug 15, 2007
Loading...

Share This Page