develooper Front page | perl.perl5.porters | Postings from April 2000

Proposed change to format for Zero Padded Numbers

From:
jpeacock
Date:
April 6, 2000 12:43
Subject:
Proposed change to format for Zero Padded Numbers
Message ID:
0004069550.AA955050753@univpress.com
I needed to use zero padded numbers for a specific project, and got a little
tired of writing sprintf("%010f", $field) for dozens of fields.  I wanted to
just use 

    format OLD_STYLE =
    @>>>>>>@####.##
    $integer, $real
    .

but have the output padded on the left with zeros instead of spaces.  

It got so bad, that I actually looked at the Perl source(!) to see if I could do
it myself.  To make a long story short, I made it work, but I wanted to discuss
the ramifications before I send in a proposed patch.  I made the following
change:

    format NEW_STYLE =
    @0######@0###.##
    $integer, $real
    .

Specifically, the @ followed by 0 followed by # would be the only case that
would trigger the FF_ZERO behavior.  I think this would be very unlikely to
break anything and would be very easy to start using.

I feel almost embarrassed to foist the patch on the list, since it was such a
trivial change.  I am also a little afraid that I will get sucked into a
wholesale replacement for Perl format ;~)

John Peacock




nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About