in reply to File ext number
Your match doesn't match when readdir returns ., so $1's value isn't changed by the match, and it was previously undefined.
use strict; use warnings; my %ext; opendir my $dh, './' or die $!; for (grep { -f } readdir $dh) { ++$ext{$1} if /\.([^.]+)$/; } print "$_ - $ext{$_}\n" for keys %ext;
Alternate:
use strict; use warnings; my %ext; opendir my $dh, './' or die $!; ++$ext{$1} for map { -f && /\.([^.]+)$/ ? $1 : () } readdir $dh; print "$_ - $ext{$_}\n" for keys %ext;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: File ext number
by toolic (Bishop) on Mar 19, 2010 at 23:38 UTC | |
by ikegami (Patriarch) on Mar 19, 2010 at 23:54 UTC |