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

@a = (1..9); @b = (a..g); @c = @a . @b; print "@c\n";
why can't I do that?

Replies are listed 'Best First'.
Re: concatenating arrays
by MZSanford (Curate) on Sep 07, 2001 at 17:50 UTC
    The reason it fails is because . is the string concatonation operator. So, to concatonate two arrays you have to be a bit more explicit. something like :
    @c = (@a,@b); # .. or , the better approach (faster) push(@c,@b,@a);

    update : corrected my stupid push mistake ... need to think before i submit. oops. thanks to those who noticed.
    can't sleep clowns will eat me
    -- MZSanford
      *BZZZZZZZT* Nope.
      # If initializing, this is clearer. my @c = (@a, @b); # .. or ... (now, more correct) my @c; push @c, @a, @b;
      push will take an array and a list, push the list onto the end of the array, and return the new number of elements.

      ------
      We are the carpenters and bricklayers of the Information Age.

      Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.