Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: compare what is in ARGV0 to a file

by Fastolfe (Vicar)
on Nov 01, 2000 at 02:22 UTC ( [id://39340]=note: print w/replies, xml ) Need Help??


in reply to compare what is in ARGV[0] to a file

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.

Replies are listed 'Best First'.
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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://39340]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2024-04-23 20:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found