in reply to Re: Calculating/adding byte counts of array elements
in thread Calculating/adding byte counts of array elements

... initialization of  $counting = '00000000'; should be satisfactory ...

Initializing  $count as a numeric string with a bunch of leading zeros will see the leading zeros vanish after the first numeric operation 'numifies' the scalar — even if it's an operation with zero!.

>perl -wMstrict -le "my $count = '00000000'; print qq{'$count'}; ;; $count += 42; print qq{'$count'}; " '00000000' '42'

Replies are listed 'Best First'.
Re^3: Calculating/adding byte counts of array elements
by Happy-the-monk (Canon) on Aug 07, 2013 at 07:41 UTC

    Initializing $count as a numeric string with a bunch of leading zeros will see the leading zeros vanish after the first numeric operation 'numifies' the scalar — even if it's an operation with zero!

    So do not numify it but use Perl's little quirks to do the trick:

    perl -wMstrict -le 'my $count = "00000000"; print qq{"$count"}; ++$count for 1 .. 42; print qq{"$count"};'

    Cheers, Sören

    Créateur des bugs mobiles - let loose once, run everywhere.
    (hooked on the Perl Programming language)