Home > Archive > PERL Miscellaneous > October 2006 > Skipping a file when perl -na is in effect
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Skipping a file when perl -na is in effect
|
|
|
| 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
| |
| Paul Lalli 2006-10-30, 7:10 pm |
| 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
| |
| xhoster@gmail.com 2006-10-30, 7:10 pm |
| "bernd" <bew_ba@gmx.net> 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
|
|
|
|
|