in reply to Re: File ext number
in thread File ext number
Here is a more verbose solution and assumes that your files are being stored in an array.
Not really.
works just as well asfor my $file (sort grep -f, readdir $dh)
for my $file (sort @files)
my $num = 1; is useless and detrimental. It reminds me of
use constant TWO => 2;
when one should rather be doing
use constant NUM_EYES => 2;
There's a point where constants become a hindrance.
should bemy $num = 1; if (exists $extensions{$key}) { $extensions{$key} += $num; } else { $extensions{$key} = $num; }
But why not just use ++? It even works great at incrementing previously undefined values.if (defined $extensions{$key}) { $extensions{$key} += 1; } else { $extensions{$key} = 1; }
++$extensions{$key};
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: File ext number
by Lady_Aleena (Priest) on Mar 20, 2010 at 03:54 UTC |