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 ]


In reply to Re: Optimize file renaming. by halley
in thread Optimize file renaming. by omega_monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.