|Think about Loose Coupling|
I am confused by a "Learning Perl" sample showing "unshift"by KenAndrews (Initiate)
|on Jan 22, 2021 at 20:41 UTC||Need Help??|
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):
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:
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.