I guess you might be storing the list of contents of a
directory in a flat file, and want to check if the current contents differ from the stored record.
In that case I would build a hash of the lines of the file like so:
%files = map { tr/\015\012//d; ($_,1); } (<FILE>);
Where FILE is an already open filehandle.
Then I would loop over the directory like so (where DIR comes from opendir):
while (defined($_ = readdir(DIR))) {
next if /^\.\.?$/;
unless (delete $files{$_}) {
print "New: $_\n";
}
}
Reporting things that weren't in the file and removing the others from the hash.
And finally reporting thing from the file that are no
longer in the directory:
for (keys %files) {
print "Gone: $_\n";
}
Of course if you are not asking for that, then your question needs clarification.
2001-03-04 Edit by Corion : Removed an erroneous <CODE> tag
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.