The way that your code is structured, the only file in the directory that will be analyzed is the first one, technically ".".
try this:
opendir(DIR, "/users/foo/")
|| die "Whoops!";
@bar = readdir(DIR);
closedir(DIR)
|| warn "Unable to close DIR";
splice(@bar, 0, 2); #get rid of '.' and '..'
And now, @bar contains all of the file names in directory '/users/foo/'. You can then use a
foreach loop or whatever to analyze the contents of that array line by line.
Hope that helps,
higle
Update: Feel free to omit the
splice bit in the above snippet for possible portability concerns. (though, this bit has been an integral part of a batch process that has been running flawlessly on my HP/UX machine every day for the last year or so, the song may not be the same for other OS flavors). I thought I'd throw that in to clean up the data, but it's not necessary for the example. Tip o' the lid to
merlyn.
Update++: In addition, my little pre-lunch break, thirty-second hack (indeed, it was hacked together in the few seconds I had before my coworkers left me to starve) has recently become the subject of another thread... It was brought up that it had absolutely
no error-checking, and indeed used a dubious hack to snip the dot and dotdot out of the array. I've replaced my nasty
for loop with a nice, tidy
splice command, and added perfunctory error checking to the
opendir and
closedir commands. I omitted those at first because I assumed they were rhetorical in such an abstract example. Assumption is the mother of all... etceteras. :)
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.