Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Answer: HOw do I compare two strings against to arrays respectively

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

Q&A > strings > How do I compare two strings against two arrays respectively? - Answer contributed by Fastolfe

If we're going against two separate files here, it might not be most efficient to slurp each file up, and do our comparisons against the file's contents. Something like the following might be more efficient:
sub check_file { my $filename = shift; my $string = shift; open(F, "< $filename") or die "$filename: $!"; while(<F>) { close(F), return 1 if /\Q$string\E/; } close(F); return } if (search_file('file1', 'string1') && search_file('file2', 'string2')) { print "OK\n"; } else { print "No\n"; }
The question title itself is referring to arrays, in which case the other responses would be more appropriate, but the question itself has to do with file contents, so I thought I'd throw this out there.

  • Comment on Answer: HOw do I compare two strings against to arrays respectively
  • Download Code
Replies are listed 'Best First'.
RE: Answer: HOw do I compare two strings against to arrays respectively
by Fastolfe (Vicar) on Nov 04, 2000 at 01:28 UTC
    Oops.. I guess that ought to be:
    sub search_file { ...
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (3)
As of 2016-12-10 00:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (159 votes). Check out past polls.