7.5. Array Assignment

You can also mix the variables on the right side and if there are arrays on the right side the whole thing becomes one flat array !

my $owner = "Moose";
my @tenants = qw(Foo Bar);
my @people = ($owner, 'Baz', @tenants);  # Moose Baz Foo Bar

my ($x, @y, @z);
($x, @y)     = (1, 2, 3, 4);    # $x is 1;  @y is (2, 3, 4)
($x, @y, @z) = (1, 2, 3, 4);    # $x is 1;  @y is (2, 3, 4)  @z is empty: ()

@y = ();                           # Emptying an array

If you are interested in on-site trainings by the author, please contact me directly.

Online courses:

Would you like to get
updated when I publish
the next article?

Follow me:

Google Plus Twitter RSS feed