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.