VSarkiss's suggestion to separate
the directory read from the file stat allows you to be
more perlish, though it won't solve your ultimate
problem (molasses-like run times on your PC).
The following idiom (adapted from an example in the Camel)
puts the names of all files called '*.log' or '*.LOG'¹ in
DIR into the @logfiles array:
my @logfiles = grep { $_ =~ /\.log$/i } readdir DIR;
You should use the /i switch in cases like this rather
than 'lc', since that changes the filename that you read
and that's not really what you want (as
tilly pointed out).
What's the spec of the PC that you're using? On our oldest,
slowest PC (P233/64Mb, Win98) this operation takes 7 minutes,
compared to just under 5 minutes on a newer but not super
slick PC (Celeron 500/32Mb, WinMe), accessing the files
over our LAN (3 mins when the files were moved to a local directory).
By contrast, this runs in less than a second
on a Sun Ultra 5...
¹(Update) It will also pick up files called *.Log, *.LOg, *.lOg, etc.
I assume that's probably not a big deal.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.