Perl one-liner: how to skip to the next file in @ARGV -
i thinking how "short circuit" reading file within perl -ne
loop. if hit condition, want abandon current file , proceed next 1 in @argv. similar gnu awk's handy nextfile
command.
something this:
perl -ne 'do_something(); next_file if some_condition()' files ...
playing around, found close argv
achieves "go next file" goal.
are there other, less magical, ways accomplish this?
nope, close argv right way this.
as noted glenn jackman, has side effect of resetting $.
line counter (which continues incrementing across several files when using argv), may want save , restore it:
my $line = $.; close argv; $. = $line;
Comments
Post a Comment