That seems like a very round-about way to check for duplicate entries, and also a very very slow one (especially on filesystems that grow much slower as the number of files in a single directory increases, and many do).
How about this construct: instead of testing for and creating files, put an entry in a hash and test for that (I'm reusing your $filename variable here, except I'm not using it as a filename):
my %seen; # declare this outside the loop
# do the following for each $filename
if ($seen{$filename}++) {
# $filename is a duplicate
}
else {
# never seen this before
}
Theoretically, that would run out of memory some time, but I can't imagine a situation where your file-based strategy would be any better. If you've got a Gb of RAM you should be able to store a couple of million "filenames" at least
updated: removed exists, added some comments
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.