You've got caught in the old = vs == trap. A single = sign sets the variable
on the left to equal that on the right, while == tests for equality. So in
your case

        $testsec{'AB'}[$i] = "6543" 

sets $testsec{'AB'}[$i] to "6543", and then returns 'true' (yes, I have
successfully set that variable). What you want is:

        if ($testsec{'AB'}[$i] == "6543") {# then do stuff}

We've all got caught out by this one (probably quite regularly).

Cheers

Mark C

> I just wonder why the if condition is always true regardless 
> of the value of the array AB.
> @AB = [1,2], and $i gets printed even for values not inlcuded 
> in array AB.
> 
> foreach $i ( 0 .. $#{ $testsec{'AB'} } ) {
>             if ($testsec{'AB'}[$i] = "6543"){ # always true!!!!
>              print "$i\n";
>             }
>             else { last ;}
>                 print " $testsec{'AB'}[$i]\n";
>             }
>             }

Reply via email to