• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

simple perl question

CTho9305

Elite Member
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
 
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 😛
...printf "filename is $_\n";
}

close SOME_VAR; # when you are done with the directory


-791-

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