[Q] $ARGV, <>, and command-line Perl

J

John W. Krahn

bill said:
Interesting topic.

I have two follow up questions regarding this:

1. Is there a simple modification of this one-liner that would short
circuit the unnecessary reading of lines when $seen{$ARGV} evaluates
to true?

perl -ne'/whatever/&&print("$ARGV\n")&&close(ARGV)'

2. A related issue is the resetting of $. . Suppose that I wanted
to check for /whatever/ only within the first 10 lines of every
file.

perl -ne'(1..10)&&/whatever/&&print("$ARGV\n")&&close(ARGV);eof&&close(ARGV)'



John
 
J

J Krugman

As usual I've learned a huge deal from the responses I received to
my original post. With Perl I'm in a perpetual state of rank
newbiehood, even though I've been programming in it for years.

Many thanks,

jill
 
C

chris-usenet

l v said:
By changing perl -ane to perl -alne you can eliminate the chomp and the
newlines from your code.

Ah. I had briefly wondered if that was possible, but hadn't even
considered the -l flag. Thanks for the heads up - it suddenly becomes
so much neater.

Chris
 

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,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top