develooper Front page | perl.perl6.language | Postings from March 2005

Re: A possible solution for s?pintf

Thread Previous | Thread Next
From:
Larry Wall
Date:
March 12, 2005 15:55
Subject:
Re: A possible solution for s?pintf
Message ID:
20050312235525.GB28769@wall.org
On Sat, Mar 12, 2005 at 11:57:39PM +0100, Juerd wrote:
: Without introduction, I'll just present the syntax idea:
: 
:     f/%03d %15s/$foo, $bar/;
: 
: This gives s?printf to any expression with short and concise syntax,
: making printf redundant, which means I won't even have to start a
: discussion about sayf :)
: 
:     printf "%03d %15s", $foo, $bar;
: 
: vs
: 
:     print f/%03d %15s/$foo, $bar/;

Well, we do already have:

    print $foo.as('%03d'), $bar.as('%15s')

which works on interpolated values as well.  It als puts the variable
name out front, since the name is more important than the pattern in
most cases.

: Of course, this is s///-like in quoting behaviour, so f[][] or f"""
: should work just as well. The RHS is not a string, but parsed as an
: expression in list context.

I don't see that this buys us anything over just shortening "sprintf"
to something shorter, like:

    print as '%03d %15s', $foo, $bar;

And your argument list falls out naturally from making "as" a listop.
Plus it naturally lets you say other "as-ly" things:

    print as MyBigInt, $foo, $bar;

: If this feels weird, just think of s///e,
: where the RHS is also not a string.

Um, actually we did away with /e in Perl 6...

Larry

Thread Previous | Thread Next


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