Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Optimize file renaming.

by halley (Prior)
on May 26, 2005 at 13:30 UTC ( [id://460674]=note: print w/replies, xml ) Need Help??


in reply to Optimize file renaming.

So far, nobody's offered glob(), so I'll throw that in there. Unless you're expecting to load several thousand filenames every few seconds, avoid the extra hassle of a readdir() loop. Since you're not even trying to save memory in your code, you should see no obvious performance difference.

Replace:

opendir(THISDIR,"e:\\perl\\comics\\"); my @comics=readdir(THISDIR); close(THISDIR);

With:

my @comics = glob('e:/perl/comics/*');

Many people work in the current directory, and specify specific wildcard masks. The "angle brackets" operator calls glob() for you (if it's not a bareword), so this might be even more readable.

my @comics = <*.png>;
Oh, and there are a few cases where Windows still really requires backslashes, but most of the time, it accepts forward slashes, Unix-style. (This has been true since MS-DOS 2.0 when it introduced subdirectories.) I find them easier to type and read.

--
[ e d @ h a l l e y . c c ]

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (3)
As of 2025-05-20 02:48 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.