Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Looking Through Arrays?

by pg (Canon)
on Dec 18, 2002 at 02:34 UTC ( [id://220739]=note: print w/replies, xml ) Need Help??


in reply to Looking Through Arrays?

I am obviously not welcomed :-) Your first line did give you a syntax error, didn't it? Other problems, which the compiler will not tell you, are the following:
  1. The quots surrounding $MemberCall and $i are not neccessary, although they do not cause problem in your case.
  2. if you set $found to "1", then you can not use == later, == is for numbers.
@AllowedRanks = ("Recruit","General","Captian","Civilian","Airman"); $found=0; my $MemberCall = "me"; foreach $i (@AllowedRanks){ if($MemberCall eq $i){ $found=1; } } if($found==1){ &Welcome; }else{ &NotWelcome; } sub Welcome { print "welcome\n"; } sub NotWelcome { print "Notwelcome\n"; }

Replies are listed 'Best First'.
Re: Re: Looking Through Arrays?
by chromatic (Archbishop) on Dec 18, 2002 at 05:15 UTC
    if you set $found to "1", then you can not use == later, == is for numbers.

    Please test your advice.

    perl will automagically attempt to convert a scalar value into the appropriate type of scalar (string or number) according to the context. It will cache the converted value in appropriate slot of the SV (scalar data structure), and will set a flag to that effect.

    In this case, it's not necessary to quote the number, but it does not prevent it from being used in numerical comparisons later -- especially as the numeric equality operator forces a numeric conversion.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2025-06-23 05:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.