I'm definitely just beginning to get my head wrapped around
perl, but I'm finally grasping many things that have eluded
me until now. That said...I've managed to hack out a script
that *almost* does what I want it to do.
#!/usr/local/bin/perl -w
opendir(DIR,".") || die "couldn't open the directory!";
@files = readdir(DIR);
closedir(DIR);
print 'There are ',scalar(@files)," files in the directory.\n";
foreach $file (@files) {
print "Stored on the server as: $file\n";
print "--------------------------------------------\n";
open (CURRENT, "$file") || die "couldn't open the file!";
while ($fileguts = <CURRENT>) {
print " $fileguts";
}
print "\n\n\n";
close(CURRENT);
}
I'm running this in a directory of text files. As you can
see, the result of this is how many files are in the
directory and the contents of each file separated with a
dashed line printed to screen. What I'd *like* to do is
only have files that have filenames ending with *.dat to be
involved.
I'm not sure if I'm on the right track or if
there's a far better way to go about this.
A key concern: this'll need to work on both an NT box
and a unix machine.
Any input is greatly appreciated.
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.