The following is the re-worked script:
----------------snip---------------------
#!/usr/bin/perl -w
use strict;
my %HoA; for ( `dir /b/s` ) { push @{ $HoA{$1} }, $2 if /(.+)\\(\w+)\.(\d+)\.(\w+)$/; }
The two last pairs of parentheses are redundant.
my %count; for my $dir ( sort keys %HoA ) { print "$dir\n"; my @basenames = @{ $HoA{$dir} }; for my $frames ( @basenames ) { $count{$frames} += 1; printf "%30s\t%04d\n", $frames, $count{$frames}; } }
Instead of that, you probably want:
for my $dir ( sort keys %HoA ) { print "$dir\n"; my @basenames = @{ $HoA{$dir} }; my %count; for my $frames ( @basenames ) { $count{$frames} += 1; } for ( sort keys %count ) { printf "%30s\t%04d\n", $_, $count{$_}; } }
I made two changes:
- The %count hash is now declared within the outer loop, since I suppose you want to have it cleared before the program starts iterating over the basenames of a new directory.
- The printf() statement has been moved to a separate inner loop. The logic bids that %count is printed only after it has been populated.
HTH
-- Gunnar Hjalmarsson Email: http://www.gunnar.cc/cgi-bin/contact.pl
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>