develooper Front page | perl.perl6.language | Postings from July 2006

sprintf and snake envy

Thread Next
Brad Bowman
July 4, 2006 00:06
sprintf and snake envy
Message ID:

It seems that sprintf is will still be around in Perl 6 [1],
and that sprintf formats will be available using the .as() method.
While looking at some Python docs [2] I noticed two things that might
be worth stealing; a sprintf operator (%) and named parameters in 
the format string:

 a = '%(lang)s has %(c)03d quote types.' % {'c':2, 'lang':'Python}

(This example made me laugh)

Since perl6 has named parameters, pairs and slurpy hashes, I think
sprintf should be taught to use them.  Syntax is an exercise for the
reader.  (Unifying the '%2$d' with the named syntax would be nice..)

The operator need is less clear cut.  Overloading '%' certainly wouldn't
make sense in Perl 6 and the presence of .as() may cover the common cases.

Some alternatives are idiomatic combinations of interpolation and .as(),
Perl6::Form forms, and custom quote operators/adverbs.

So, any takers?


    Search for: "Format operator"
 Bravery and cowardice are not things which can be conjectured in times
 of peace.  They are in different categories. -- Hagakure

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About