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

Re: A possible solution for s?pintf

Thread Previous | Thread Next
From:
Brent 'Dax' Royal-Gordon
Date:
March 12, 2005 15:51
Subject:
Re: A possible solution for s?pintf
Message ID:
b8b9a51105031215511f703b6d@mail.gmail.com
Juerd <juerd@convolution.nl> wrote:
> Without introduction, I'll just present the syntax idea:
> 
>     f/%03d %15s/$foo, $bar/;
> 
> 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. If this feels weird, just think of s///e,
> where the RHS is also not a string.

I think s///e is going away, since you can just use s/pattern/{code}/
now anyway.

Besides, I think "as" will do just fine, especially since you can now
interpolate method calls as well.  You can even do something like this
if you want to perform bulk formatting:

    say join ' ', ($n1, $n2, $n3) >>.as('%d');

Or, if that's not quite sufficient:

    say map { .key.as(.value) }
        $num => '%d',
        $str => '%s',
        ...;

-- 
Brent 'Dax' Royal-Gordon <brent@brentdax.com>
Perl and Parrot hacker

"I used to have a life, but I liked mail-reading so much better."

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