Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: readdir

by Speedy (Monk)
on Oct 29, 2002 at 19:49 UTC ( [id://208852]=note: print w/replies, xml ) Need Help??


in reply to filtering readdir()'s results

Perldoc is your friend here.

From your $dir path, looks like you are on windows. So go to a DOS prompt, enter:

perldoc -f readdir

and you will see by happy coincidence as the example in the last paragraph an answer to your question:

-------------------------

If you're planning to filetest the return values out of a "readdir", you'd better prepend the directory in question. Otherwise, because we didn't "chdir" there, it would have been testing the wrong file.

opendir(DIR, $some_dir) || die "can't opendir some_dir: $!"; @dots = grep { /^\./ && -f "$some_dir/$_" } readdir(DIR); closedir DIR;

------------

Just replace the ^\. with ^xxxx and your job is done, like:

opendir(DIR, $some_dir) || die "can't opendir $some_dir: $!"; @xxxx = grep { /^xxxx/ && -f "$some_dir/$_" } readdir(DIR); closedir DIR; print "@xxxx";

Live in the moment

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://208852]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (3)
As of 2025-06-14 17:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.