Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Answer: compare what is in ARGV0 to a file

( #39340=categorized answer: print w/ replies, xml ) Need Help??

Q&A > strings > compare what is in ARGV[0] to a file contributed by Fastolfe

Be aware that each element in @lines will have the trailing newline from the file. You probably want to chomp(@lines); before you compare it against anything.

In addition, your grep statement is non-sensical. See the documentation for it. If you want to loop through @lines and compare it against $ARGV[0] (why not $zero_arg?), you'll have to either explicitely set up a loop to do it, or modify your grep statement to compare against $_, which will iteratively contain each element in @lines in turn.

Comment on Answer: compare what is in ARGV0 to a file
Select or Download Code
RE: Answer: compare what is in ARGV0 to a file
by arturo (Vicar) on Nov 01, 2000 at 02:28 UTC

    To amplify Fastolfe's point ... your grep grabs everything in the array, for the simple reason that the line immediately preceding it sets $zero_arg equal to $ARGV[0] (you thus get every line which is such that the first argument passed to the script is the same as the first argument passed to the script). If your first argument is the thing you're looking for in the file, this is obviously no good. use $_ as Fastolfe suggests, that's the "default variable".

    Philosophy can be made out of anything. Or less -- Jerry A. Fodor

Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (3)
As of 2014-07-26 11:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (175 votes), past polls