simple perl question

CTho9305

Elite Member
Jul 26, 2000
9,214
1
81
how do I loop over every file in the directory? I want to create a nice-looking listing.
pseudo-code:

foreach file in the directory
{
make it pretty
}

I dont have a perl book to look through ;)
thanks
 

stndn

Golden Member
Mar 10, 2001
1,886
0
0
for perl references, see here
you don't have a perl book? are you sure you don't have a perl book? ;)

anyways, here's how you do it:

opendir (SOME_VAR, "/full/path/to/the/directory");
# you may want to add some check here, to make sure the directory is opened correctly

foreach (readdir SOME_VAR) {
...# this is optional, if you want to skip some files (eg: in unix, if you want to skip . and ..)
...next if ($_ eq "." || $_ eq "..");

...# this display the output ... sure, it's not pretty, but whatever :p
...printf "filename is $_\n";
}

close SOME_VAR; # when you are done with the directory


-791-

edit: forgot to open directory before reading it ...