It's not actually a foreach problem.
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 = </xxx/*> print join ':', @dirvar;
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.my @dirvar = glob "/xxx/{.,}*";
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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |