Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

compare what is in ARGV[0] to a file

( #39338=categorized question: print w/ replies, xml ) Need Help??
Contributed by dallok on Nov 01, 2000 at 02:12 UTC
Q&A  > strings


Description:

I want to compare what is in $ARGV[0] an array that I created from a file that contains single line entries.

This is what I have so far:
#!c:\perl\bin -w use strict; open downfile, '>f:\scripts\text\nodedown.txt': print downfile "$ARGV[1] $ARGV[2] is Down on $ARGV[0].\n"; close downfile; my $routers="F:/scripts/text/routers.txt"; open routers, $routers or die "cannot open $routers: $!\n"; my @lines = <routers>; close routers; my ($zero_arg, $first_arg, $sec_arg) = @ARGV[0..2]; if (grep {$zero_arg eq $ARGV[0]} @lines) { system('f:\usr\ov\bin\nvecho.exe GOT IT'); } exit 0;
Is there a better way to do this?

Answer: compare what is in ARGV0 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.

Answer: compare what is in ARGV0 to a file
contributed by Ovid

dallok: this appears to be at least the third time that you have asked a variation of this question. I think you would be better served posting this to the Seekers of Perl Wisdom section. Then, rather than post it three times (with little to no explanation), you could generate a running commentary where people ask "What are you talking about?" and you get a chance to clarify it, rather than repeatedly posting "non-questions" like the one above.

Please (register and) log in if you wish to add an answer



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • 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 wandering the Monastery: (3)
    As of 2014-09-23 05:21 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      How do you remember the number of days in each month?











      Results (210 votes), past polls