It's not actually a foreach problem.

my @dirvar = </xxx/*> print join ':', @dirvar;
It's a glob problem. Which reminds me - I recommend avoiding the <...> operator for that. Not just because it's a pain to type and get to display properly here ;-), but because using "glob" is so much more obvious as to what you're doing. (<...> is implemented in terms of glob, so this doesn't change anything functionally)
my @dirvar = glob "/xxx/*";
Looking up glob in the perlfunc documentation (e.g., "perldoc -f glob"), you see it is implemented via File::Glob. Looking that up, you see it tries to implement C shell semantics. This sets off warning bells: on unix, files with a leading dot are considered "hidden" and should not be shown by default. So "*" does not match leading dots. Other dots, but not leading dots. Looking C shell up (I'm a Korn shell/Bourne-again shell type of guy m'self), I see that this should work:
my @dirvar = glob "/xxx/{.,}*";
The reason? Braces denote choices, all of which apply. The comma separates the choices. So this expands to both "/xxx/.*" and "/xxx/*" simultaneously, in a single call.

readdir, by the way, does not use shell semantics, and thus ignores "hidden" attributes, laying everything out for you.

HTH


In reply to Re: foreach and opendir differences by Tanktalus
in thread foreach and opendir differences by dobby

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.