in reply to Re: unshift single scalar
in thread unshift single scalar

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:

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"]
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.