I am doing some work in Perl, and I came across an odd result with a conditional statement.
The code in question:
($foo eq "blah") ? @x = @somearray : @y = ("another","array");
Attempting to compile this code results in an error " Assignment to both a list and a scalar at XXX line YY, near ');'". Trying to determine the source of the error, I wrote this using a couple of different ways to represent the array in Perl, and they all return with the same error. Now at first I thought it was just some kind of stupid explicit mistake with assignment statements, but to satisfy my curiosity, I rewrote the expression in more detail:
if($foo eq "blah") {
@x = @somearray;
} else {
@y = ("another","array");
}
This version of the code compiled perfectly.
- , if-else, ? . , Perl , ?