Reading a directory all at once with an array: Use an array with the readdir command, instead of a scalar variable : file read « File « Perl
- Perl
- File
- file read
Reading a directory all at once with an array: Use an array with the readdir command, instead of a scalar variable
#!/usr/bin/perl -w
$name = "c:\\";
opendir(DIR, $name) or die "Can't open $name due to $!";
@entries = readdir(DIR);
closedir(DIR);
# Sort results.
@sorted = sort(@entries);
foreach $entry (@sorted) {
print "$entry\n";
}
Related examples in the same category