Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

next unless - doesnt work?

by sweepy838 (Acolyte)
on Apr 28, 2012 at 14:32 UTC ( #967814=perlquestion: print w/ replies, xml ) Need Help??
sweepy838 has asked for the wisdom of the Perl Monks concerning the following question:

So i have:
next unless ( grep( /$name/, @names )); print "$name isnt in the array so continue";
it prints nothing, even though the name is there. however, this works:
if ( grep( /$name/, @names )) { print "name is in the array"; } #but this doesnt suit my needs.
thx for help :)

Comment on next unless - doesnt work?
Select or Download Code
Re: next unless - doesnt work?
by brx (Pilgrim) on Apr 28, 2012 at 15:01 UTC

    Show us the complete loop. "If LABEL is omitted, the command refers to the innermost enclosing loop" (next)

    update: better to do grep {$name eq $_} @names

      ah i solved the problem using ne instead of eq :) and for some reason != didnt do the job but ne did.. strange?

        Not strange ;)

        != and == are for numeric context comparisons where eq/ne are for evaluating strings.

        Your original post didn't show any code relating to evaluations, so I, nor anyone else have any idea how this was part of your problem in the first place.

        and for some reason != didnt do the job but ne did.. strange?

        Not at all. One is for numbers, the other for strings. You would've gotten a warning if you had use warnings on.

        String vs numerical
        Not at all strange: ne is used for alphas; != for numbers.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (4)
As of 2014-09-16 06:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (157 votes), past polls