You can do it either way, as jettero showed:
@list = (@list, bsd_glob ("$DIR/*XYZ", GLOB_QUOTE )); ... push @list, bsd_glob ("$DIR/*XYZ", GLOB_QUOTE ));

(Update:  Replaced the code sample I inadvertently copied from the OP with the one I meant to copy, from jettero).

But there's an interesting difference which becomes very clear for very large lists, which is that using push is more efficient.

For example, running the following takes about 1 second for the subroutine list_push to run, but 3 to 5 seconds for the subroutine list_combine:

use strict; use warnings; my $size = 1_000_000; list_push(); #list_combine(); sub list_combine { print "Creating list1 ...\n"; my @list1 = ( "a" ) x $size; print "Creating list2 ...\n"; my @list2 = ( "b" ) x $size; print "Concatenating lists...\n"; my $start = time; @list1 = (@list1, @list2); my $elapsed = time - $start; my $size = @list1; print "List size = $size, elapsed = $elapsed second(s)\n"; } sub list_push { print "Creating list1 ...\n"; my @list1 = ( "a" ) x $size; print "Creating list2 ...\n"; my @list2 = ( "b" ) x $size; print "Pushing lists...\n"; my $start = time; push @list1, @list2; printf "Elapsed = %d\n", time - $start; my $elapsed = time - $start; my $size = @list1; print "List size = $size, elapsed = $elapsed second(s)\n"; }

It gets much worse for $size = 2_000_000, where list_combine causes my computer thrash as it runs out of available memory.


s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/

In reply to Re: Can't modify private array in concatenation? by liverpole
in thread Can't modify private array in concatenation? by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.