in reply to question regarding slices

You could use grep, like this
foreach(grep ! /^\.{1,2}$/, readdir(PRINT)){ #do work }
but it loops through the list twice, which may be a little inefficient, so you could use glob which removes the . and .. automatically.
my $dir = '/path/to/dir'; foreach(glob('$dir/*')){ #do work }
I prefer using glob().

As for retrieving all but the first 2 elements of the list, it is a little akward, so you could assign them into an array and do this
my @array = readdir(PRINT); foreach(@array[2..$#array]){ #do work }

- Tom

Replies are listed 'Best First'.
Re:x2 question regarding slices (don't use regexps to filter . and ..)
by grinder (Bishop) on Nov 06, 2003 at 21:54 UTC

    Don't use grep to filter out these entries. Unless you know what you are doing, you open yourself to security problems (missing a directory you should traverse). And if you do know what you are doing, it looks strange to someone who doesn't, and so they might want to "fix" it and hence break it.

    More discussion about this issue can be found at:

    And in case the OP isn't aware of them, this might be the right moment to mention File::Find and File::Find::Rule.