in reply to Strange "Useless use of constant" message: should not appear at all!
You can't compare arrays/lists for equality directly. The == and eq operators work on scalars, so @movement and (0, 1) are both being evaluated in scalar context. Of course, (0, 1) in scalar context simply throws away the 0, which is the source of the error.@movements == (0, 1);
If you want to compare these arrays for equality, since they are so simple, you can stringify them:
Or a more general comment, even use a lookup table:local $" = ","; if ("@movement" eq "0,1") { ... } elsif ("@movement" eq "1,0") { ... } ...
local $" = ","; my %dir = ( "0,1" => "north", "1,0" => "east", "0,-1" => "south", "-1,0" => "west" ); $from = $dir{"@movement"};
blokhead
|
|---|