in reply to Help needed with Perl script designed to find files by extension and count the number of chars

Others have answered what was wrong, i wanted to show you a completely better way to solve the problem:

use strict; use warnings; use File::Find::Rule; my @found = File::Find::Rule ->file() ->name( map "*$_", @ARGV ) ->in( '.' ) ; print scalar( @found ), $/;
I covered the first requirement, all you need is a loop to process the char count from the files found. But ... why do you need this information? Wouldn't du -h provide the information you need without having to develop another solution?

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)
  • Comment on Re: Help needed with Perl script designed to find files by extension and count the number of chars
  • Download Code

Replies are listed 'Best First'.
Re^2: Help needed with Perl script designed to find files by extension and count the number of chars
by Anonymous Monk on Apr 30, 2015 at 18:32 UTC

    The memory efficient version

    #!/usr/bin/perl -- use strict; use warnings; use File::Find::Rule qw/ find rule /; my $count = 0; my $size = 0; rule( file => name => [ map {"*$_"} @ARGV ], exec => sub { ## my( $shortname, $path, $fullname ) = @_; $size += -s _; ## or use $_ $count++; return !!0; ## means discard filename }, )->in('.');