Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re^2: Perl Directory file extension stats.

by kcott (Abbot)
on Apr 16, 2014 at 00:47 UTC ( #1082412=note: print w/ replies, xml ) Need Help??


in reply to Re: Perl Directory file extension stats.
in thread Perl Directory file extension stats.

Assuming a %stats hash has been declared, the File::Find callback can be as simple as:

sub wanted { return unless -f; /(?<!^)[.]([^.]+)$/; ++$stats{$File::Find::dir}{$1 || ''}; }

That will cause all files without an extension, as well as hidden files without an extension (e.g. .bashrc), to be counted together under a '' key. Everything else will counted under keys without a leading '.', e.g. 'pl', 'txt', 'png', etc.

If counts for individual directories aren't required, that can be simplified even further by just using:

++$stats{$1 || ''};

-- Ken


Comment on Re^2: Perl Directory file extension stats.
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1082412]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (8)
As of 2014-12-20 11:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (95 votes), past polls