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

Case1:No issue

my @array1=(1,2,3); my @array2; @array2=(@array1,4,5,6); print"@array2\n";

This printed 1 2 3 4 5 6 which is expected

Case2:I tried to extend this to qw and reason for my question

my @array1=qw(Jan Feb Mar); my @array2; @array2=qw(@array1 Jan Feb Mar); print"@array2\n";

This printed @array1 Jan Feb Mar

Am i missing any basic thing here. How to stuff array1 contents inside array2 when qw is used?Thanks

Replies are listed 'Best First'.
Re: stuffing an array inside a list
by Grimy (Pilgrim) on May 26, 2013 at 01:34 UTC

    qw doesn't perform any interpolation: anything inside a qw is interpreted as litteral characters (with two minor exceptions: \\ and \delimiter). That's why you got this output: inside a qw, @array1 is no more special than Jan. Try this:

    @array2 = (@array1, qw(Jan Feb Mar));

    Alternatively, you could use push, like so:

    my @array2 = @array1; push @array2, qw(Jan Feb Mar);
Re: stuffing an array inside a list
by NetWallah (Canon) on May 26, 2013 at 01:37 UTC
    "@" does not interpolate inside "Quote like operators" (qw).

    Update - corrected to allow for qq, per Grimy(++) below.

                 "I'm fairly sure if they took porn off the Internet, there'd only be one website left, and it'd be called 'Bring Back the Porn!'"
            -- Dr. Cox, Scrubs

      While it is true that @ doesn't interpolate inside qw, it does interpolate inside qq, which is also a “Quote-like operator”.