Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

Answer: compare what is in ARGV0 to a file

by Fastolfe (Vicar)
on Nov 01, 2000 at 02:22 UTC ( #39340=categorized answer: print w/replies, xml ) Need Help??

Q&A > strings > compare what is in ARGV[0] to a file - Answer 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.

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?

What's my password?
Create A New User
[marto]: hmm, I wonder who is actually checking for such things

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (5)
As of 2018-01-18 11:03 GMT
Find Nodes?
    Voting Booth?
    How did you see in the new year?

    Results (211 votes). Check out past polls.