http://qs1969.pair.com?node_id=11127306

KenAndrews has asked for the wisdom of the Perl Monks concerning the following question:

I am starting to learn Perl by reading "Learning Perl" and testing on a Centos box.

I typed in a piece of code from the book and it did exactly what the book said it should do... But I don't know why!

This is the code I typed in (modded to my coding requirements):

use strict; use warnings; my @lArray; my @lNums = 1..3; unshift @lArray, 5; print "Array: @lArray\n"; unshift @lArray, 4; print "Array: @lArray\n"; unshift @lArray, @lNums; print "Array: @lArray\n";

The output of the third print is "Array: 1 2 3 4 5", exactly as the book showed. My question is why is it that way? After thinking about it my expectation was that it would be "Array: 3 2 1 4 5".

I expected "unshift @lArray, @lNums" to expand to "unshift @lArray, 1 2 3" and then be processed as though:

unshift @lArray, 1 unshift @lArray, 2 unshift @lArray, 3

However, it doesn't. It looks like the unshift operation is processing the values given in reverse order (3 2 1). Is this true? If not, how is it putting them in in the given order rather than reversed?

Anyway, that's my problem; totally confused by Chapter 3.