Here are some examples that may help drive the point home:
c:\@Work\Perl\monks>perl -wMstrict -MData::Dump -le "my @output = qw(OldTop Second Third); dd \@output; ;; unshift @output, 'NewTop'; dd \@output; ;; my @otherarray = qw(uno dos tres); unshift @output, @otherarray; dd \@output; " ["OldTop", "Second", "Third"] ["NewTop", "OldTop", "Second", "Third"] ["uno", "dos", "tres", "NewTop", "OldTop", "Second", "Third"]
... a more elegant way ...
I don't know if you will consider this more elegant or not:
The disadvantage of this approach is that it requires the construction of a temporary list, which in the case of a large @output array will be correspondingly large.c:\@Work\Perl\monks>perl -wMstrict -MData::Dump -le "my @output = qw(OldTop Second Third); dd \@output; ;; @output = ('NewTop', @output); dd \@output; " ["OldTop", "Second", "Third"] ["NewTop", "OldTop", "Second", "Third"]
In reply to Re^2: unshift single scalar
by AnomalousMonk
in thread unshift single scalar
by Bodger
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |