in reply to Directory Listing to an Array

This is *dangerous* code snippet, because it corrupts value of $_ variable by while($_=readdir).
(didn't you read "seven sins of perl (revisited)?")
You should place local $_ somewhere at the beginning of a sub. Or write instead of "while" ..... for (readdir) which will localize $_ itself.

Replies are listed 'Best First'.
Re: Re: Directory Listing to an Array
by Anonymous Monk on Feb 28, 2003 at 02:37 UTC

    $map = 'c:\\some\\directory'

    opendir (Directory, $map) or die "Cannot Open Directory";

    @contents = readdir(Directory);

    closedir(Directory);

    splice(@contents, 0, 2);  # removes " . & .. "

    foreach $content (@contents) {

        print "$content\n";

    }

    I have used this to capture the contents of a directory... Darrick...