0: This code came from my desire to use perl for something
1: besides CGI, which is my current perl-y focus.
2: I expected slightly different behavior from
3: File::Find::file, though this may be my Win background
4: shining through.
5: Put simply, this will traverse a filesystem, and determine
6: the # of files based on extention. Again, this was more to
7: keep the programming muscles limber; I plan on using this as a shell for more complex things. I do appreciate any
8: comments you have, however.
9: <code>
10: #use warnings;
11: use strict;
12: use File::Find;
13:
14: my %hash;
15: my @temp;
16:
17: File::Find::find (\&wanted,"c:\\");
18: my @keys = keys (%hash);
19: @keys = sort_by_value (\%hash);
20:
21:
22: print "-"x20,"\n";
23: foreach my $key(@keys) {if ($key =~ /^$/) {print "no ext\t:\t"}else{ print "$key\t:\t"}; print $hash{$key},"\n"}
24:
25: sub sort_by_value {
26: my %hash = %{shift()};
27: sort {$hash {$a} <=> $hash{$b} } keys %hash;
28: }
29:
30:
31: sub wanted {
32: my @file ;
33: my $fname;
34: # don't attempt to read a directory.
35: if (-d $_) {return};
36: $fname = $File::Find::name;
37: # turn any '/' into a '\'
38: # then make sure that any '\\' get turned into '\'
39: $fname =~ s#\/#\\#g;
40: $fname =~ s#\\\\#\\#;
41: @temp= split /\./, $_;
42: # mmm. autovivification
43: $hash{@temp[1]}++
44: }
45: </code> In reply to file ext counter. by boo_radley
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |