"be consistent" PerlMonks

### compare what is in ARGV&#91;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; [download] Is there a better way to do this?  Answer: compare what is in ARGV0 to a filecontributed 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 filecontributed 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.

• Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
• Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
• Read Where should I post X? if you're not absolutely sure you're posting in the right place.
• 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
• You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
 For: Use: & & < < > > [ [ ] ]
• Link using PerlMonks shortcuts! What shortcuts can I use for linking?

Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (6)
As of 2015-11-27 22:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?