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

Tip #2 from the Basic debugging checklist: print. The reason you get no output is that $tmpfilecount is 0. $tmpfilecount is 0 because you set it to 0 in your foreach loop, then you never change its value. The only thing you do with the variable is pass it as an input to your countThem sub.

  • Comment on Re: Help needed with Perl script designed to find files by extension and count the number of chars

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 Athanasius (Archbishop) on Apr 30, 2015 at 14:55 UTC

    Hello toolic,

    The only thing you do with the variable is pass it as an input to your countThem sub.

    Yes, but the variable $tmpfilecount is a package global (no my in sight, as you note), and within sub countThem the variable $_[0] is an alias to the variable passed as the first argument. Therefore the line:

    $_[0]=$filecount;

    within the sub actually should change $tmpfilecount to the value of $filecount. Proof of concept:

    0:42 >perl -wE "sub f { ++$_[0] } $x = 42; f($x); say $x;" 43 0:43 >

    So the problem is that $filecount is never incremented.

    Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,