Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Array splitting

by AnomalousMonk (Monsignor)
on Oct 31, 2012 at 22:00 UTC ( #1001750=note: print w/ replies, xml ) Need Help??


in reply to Array splitting

... it skips the if in the foreach loop.

When I run your OPed code, I see that the  else (false) clause of the conditional statement is skipped, not the  if (true) clause, which is always executed.

The reason is that you are using a numeric  == comparison to test for string equality. You should use the  eq operator (see Equality Operators in perlop). Numeric comparisons of strings that have no leading decimal digits are always equal because such strings always evaluate to zero in numeric context.

>perl -wMstrict -le "print 'A' == 'B'; " Argument "B" isn't numeric in numeric eq (==) at -e line 1. Argument "A" isn't numeric in numeric eq (==) at -e line 1. 1

And BTW: using warnings would have alerted you to this problem, and using strict ain't a bad idea, either.


Comment on Re: Array splitting
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (7)
As of 2014-08-23 04:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (172 votes), past polls