Skipping a file when perl -na is in effect

B

bernd

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
 
P

Paul Lalli

bernd said:
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
 
X

xhoster

bernd said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,825
Latest member
VernonQuy6

Latest Threads

Top