Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Re: Perl Directory file extension stats.

by Laurent_R (Canon)
on Apr 15, 2014 at 22:06 UTC ( #1082397=note: print w/replies, xml ) Need Help??

in reply to Perl Directory file extension stats.

The File::Find module should, I think, be able to give you the answer if you provide it with the right callback function.
  • Comment on Re: Perl Directory file extension stats.

Replies are listed 'Best First'.
Re^2: Perl Directory file extension stats.
by kcott (Chancellor) on Apr 16, 2014 at 00:47 UTC

    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

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1082397]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2018-06-23 05:12 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (125 votes). Check out past polls.