In your first example, $a is set to the last element because a list in scalar context returns the last element. In your second example, you have a really oddball truth value thing. Ranges in scalar context do things I don't easily comprehend (read perlop for further info).
I'm really not sure what perl does with (a..c). I usually use strict which would not allow that and I usually use warnings, which would explain some other things you have working against you. I think 'a' and 'c' are strings in your example, not totally sure.
Here are some interesting examples:
use strict; #use warnings; my $x = (1,2,3); # $x is 3, list in scalar context my @y = (4 .. 6); # @y is (4,5,6); my $y = @y; # $y is 3, array in scalar context my $z = 0 .. 0; # $z is true my $w = 1 .. 3; # $w is false print "$x, $y, $z, $w\n";
You will get lots of warnings with the above if you turn on warnings.
-Paul
In reply to Re: scalar slice assignment doubt
by jettero
in thread scalar slice assignment doubt
by perlstarter
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |