Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

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

by runrig (Abbot)
on Nov 04, 2000 at 00:39 UTC ( #39903=categorized answer: print w/replies, xml ) Need Help??

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

grep (or map) in a void context is generally considered bad. Better to store the array in a hash, especially if you access it more than once:
my %file; @routers{@ARRAY} = undef; @interfaces{@anotherarray} = undef if (exists $routers{$zero_arg} and not exists $interfaces{$sec_arg)) { #Do stuff }

  • 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 runrig (Abbot) on Nov 04, 2000 at 00:44 UTC
    Re-reading your problem (and if I understand it correctly), I'd do it this way:
    my %file; @routers{@ARRAY} = undef; die "Bad zero_arg" unless exists $routers{$zero_arg}; my %interfaces; @interfaces{@anotherarray} = undef; unless (exists $interfaces{$sec_arg)) { #Do stuff } # OR this, if appropriate return if exists $interfaces{$sec_arg}; #Do stuff
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
[ambrus]: So that, or if you really want something agnostic to the loop, then use curl multi. Its interface is quite reasonable (unless you use an old version),
[ambrus]: though it's very C-like (serious use of varargs so easy to pass the wrong type), and there are some minor problems (busy loop because it doesn't use the same timer as your event loop, so you have to artificially delay timer callbacks by a small amount).

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













    Results (130 votes). Check out past polls.