On Fri, 20 Apr 2007 21:26:33 +0100
Andy Armstrong <[EMAIL PROTECTED]> wrote:

> > An interesting idea, but what does that buy you that a plain  
> > sprintf does
> > not?
> >
> >   $pr->build( { ALBUM => sprintf("%04d", $album),
> >                 PHOTO => sprintf("%04d", $photo) } )
> 
> It encapsulates the formatting requirement where it belongs - with  
> the rest of the specification for that string.

I guess there is that; this would seem a good place to do that.

But, I am slightly reluctant to do that, for the following reason.
Without those printf formats, there is a large invariant symmetry
here:

  my $pr = Parse::Reversible->new( 'any format you like' );

  $str  == $pr->build( $pr->parse( $str  ) );

  $vars == $pr->parse( $pr->build( $vars ) );

With format specifiers, we'd break that.

> I agree that it's not massively general - but you could use it to
> 
> * generate fixed width fields
> * truncate reals to ints
> * specify the number of decimal places

Mmm... Though those do sound like quite useful things to have the ability
to do...

Are we sure on the notation format though? It gets quite hard to parse by
this stage if we have

  ${NAME:pattern:format}

if only that, what happens if we want a literal : in our pattern - do we
need to escape it?

Or maybe to make it look more like a pattern, we might try

  ${NAME/pattern/format}

-- 
Paul "LeoNerd" Evans

[EMAIL PROTECTED]
ICQ# 4135350       |  Registered Linux# 179460
http://www.leonerd.org.uk/

Attachment: signature.asc
Description: PGP signature

Reply via email to