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

I would like to know if it was possible to assign 2 arrays - @skeyw and @skeyw2 - to the same scalar so that both arrays contain the same information.
(@common) = split(/ /,$fields{'keywords'});
into perhaps
(@common, @common2) = split(/ /,$fields{'keywords'});

Replies are listed 'Best First'.
Re: Assigning 2 arrays to scalar
by Zaxo (Archbishop) on Jun 30, 2004 at 01:53 UTC

    Your title is a little misleading, I think.

    Your idea will assign everything in the split list to @common and leave @common2 empty. Here, this does what I think you want, @common2 = @common = split ' ', $fields{'keywords'}; I changed the split to magic split, just in case. If you're right about there just being one space in all cases, there is no harm done.

    After Compline,
    Zaxo

Re: Assigning 2 arrays to scalar
by spurperl (Priest) on Jun 30, 2004 at 06:44 UTC
    Your title is very misleading - please consider changing it.

    split returns an array, not a scalar. You can evaluate it in a scalar context if you like, but that's probably not your goal, according to the code you present (@ is for arrays).