my( $a, $b, $c ) = ( 1, 2, 3);
$a = $b = $c = 1;
print "$a$b$c";
####
my($a,$b) = (23, 99);
$a ^= $b ^= $a ^= $b;
print "$a : $b";
99 : 23
####
#! perl -slw
use strict;
sub swab {
substr( $_[0], $_[1], 1,
substr( $_[0], $_[2], 1,
substr( $_[0], $_[1], 1 )
)
);
}
my $s = 'AB';
swab( $s, 0, 1 ), print "'$s'" for 1 .. 10;
__END__
P:\test>test
'BA'
'AB'
'BA'
'AB'
'BA'
'AB'
'BA'
'AB'
'BA'
'AB'
####
Assignment operators work as in C. That is,
$a += 2;
is equivalent to
$a = $a + 2;
although without duplicating any side effects that dereferencing the lvalue might trigger, such as from tie(). Other assignment operators work similarly. The following are recognized:
**= += *= &= <<= &&=
-= /= |= >>= ||=
.= %= ^=
x=
Although these are grouped by family, they all have the precedence of assignment.
Unlike in C, the scalar assignment operator produces a valid lvalue. Modifying an assignment is equivalent to doing the assignment and then modifying the variable that was assigned to. This is useful for modifying a copy of something, like this:
($tmp = $global) =~ tr [A-Z] [a-z];