This line:
use warnings;
use strict;
use File::Find;
my %hash;
my @temp;
my $dir = shift @ARGV;
die "Give me a directory to search\n" unless (-d "$dir");
File::Find::find (\&wanted,"$dir");
print "-"x20,"\n";
foreach my $key (sort keys %hash) {
print $key, "\t:\t",$hash{$key},"\n";
}
sub wanted {
# don't attempt to read a directory.
return if (-d $_);
my $fname = $File::Find::name;
@temp = split(/[\/\\]/, $fname);
$fname = $temp[-1];
# Make sure there is an extension. We check for a
# trailing period even though on Win32 it shouldn't happen
if (($fname =~ /\./) && !($fname =~ /\.$/)) {
$fname = lc($fname);
@temp= split(/\./, $fname);
$hash{$temp[-1]}++;
}
else {
$hash{"no ext"}++;
}
}
Update:
I Changed a few more things around. I went right for the filename since a "." in a directory could mess things up as well.
$array[-1] so that we don't have troubles with files like "blah.txt.sh".
And we now account for no extension at all.
This code could make use of File::Basename as well.
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.