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

Re: if statement comparing elements of arrays?

by si_lence (Deacon)
on Jul 14, 2009 at 09:32 UTC ( #779851=note: print w/ replies, xml ) Need Help??


in reply to if statement comparing elements of arrays?

Your code works for me

use strict; use warnings; #compare the commands in the arrays my @commands_run = qw(first second third fourth fifth); my @commands = qw(first second third fourth fifth); if (($commands_run[0] =~ /$commands[0]/) &&($commands_run[1] =~ /$commands[1]/) &&($commands_run[2] =~ /$commands[2]/) &&($commands_run[3] =~ /$commands[3]/) &&($commands_run[4] =~ /$commands[4]/)) { print "Test -----PASS\n"; } else { print "Test ---- FAIL\n"; }
prints
Test -----PASS
So maybe your two arrays are not the same after all.
Maybe print them with Data::Dumper to confirm?

Cheers, si_lence


Comment on Re: if statement comparing elements of arrays?
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://779851]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (12)
As of 2015-07-02 10:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (34 votes), past polls