The built-in glob splits its arguments on whitespace, so one might think of this as a possibility, but especially since you seem to be on Windows, I wouldn't be surprised if the pathnames contain spaces. I would recommend bsd_glob from File::Glob instead, which does not split on whitespace:

use File::Glob 'bsd_glob'; my @files = ( bsd_glob("$Dir1/*"), bsd_glob("$Dir2/*") );

You can also use File::Glob ':bsd_glob'; to override the builtin glob (except on really old versions of Perl). Another possible caveat of glob to be aware of is that it does not list files beginning with a dot by default.

Update: Another possibility might be: my @files = bsd_glob("{$Dir1,$Dir2}/*"); Also a few edits to add a bit of info.

Update 2: An even bigger possible caveat that should be mentioned is that of course all this assumes that $Dir1 and $Dir2 don't contain any characters that have special meaning to glob. If that is the case, I'd recommend other methods like Path::Class::Dir's children method (this will include filenames beginning with a dot, use ->children(no_hidden => 1) to suppress them):

use Path::Class qw/dir/; my @files = ( dir($Dir1)->children, dir($Dir2)->children );

In reply to Re: list two paths files into one array (updated) by haukex
in thread list two paths files into one array by ytjPerl

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.