in reply to Re^2: selcting all files in a given directory except......
in thread selcting all files in a given directory except......
If you want more robust, don't use a regexp to match parent and current directories.
@files = grep {$_ ne '.' and $_ ne '..'} readdir($D);
I know one isn't meant to write code that is easy for a monkey to understand, but all the same, I don't think the added complexity of throwing in a couple of more-rarely used regops like \z and (?!...) is worth it in this case.
This way there is no ambiguity with strange directories like "foo\n.". Also, your original solution may fail if a corrupted filesystem is rebuilt, and the parent and current directories pointers are rewritten elsewhere than positions 1 and 2 in the directory list.
If you want to go really cross-platform robust, use File::Spec's curdir() and updir() routines.
• another intruder with the mooring in the heart of the Perl
|
|---|