12/7/2017 - 10:00 AM

Assigning scalars to arrays

Each scalar variable in the list takes on the corresponding value from the list on the right side of the assingment.

($a, $b, $c) = (1, 2, 3) # give 1 to $a , 2 to $b and 3 to $c
($a, $b) = ($b, $a) # swap the values of $a and $b
($d, @fred) = ($a, $b, $c) # give $a to $d and ($b, $c) to @fred 
($e, @fred) = @fred # remove first element of @fred ($b) and give it to $e
                    # so @fred is now = $c and $e = $b
# NOTE: array variables in array literal lists must be last. 
# Otherwise, the variables placed after will be given undef values.
# This is because the array consumes all remaining values