Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^2: what would you like to see in perl5.12?

by phaylon (Curate)
on Aug 07, 2008 at 13:53 UTC ( #702883=note: print w/ replies, xml ) Need Help??


in reply to Re: what would you like to see in perl5.12?
in thread what would you like to see in perl5.12?

Wouldn't that break lots of (s)printf formats?


Ordinary morality is for ordinary people. -- Aleister Crowley


Comment on Re^2: what would you like to see in perl5.12?
Re^3: what would you like to see in perl5.12?
by BrowserUk (Pope) on Aug 07, 2008 at 15:55 UTC

    As I originally proposed it, I don't think it would. In any legal printf format, % is followed one of %*+- #csduoxefgXEGbpniDUOF\d..

    Which I think means that %{...} would not conflict with any existing formats, and would generate: Invalid conversion in printf: "%{" if it appeared in any existing code. The lack of backwards compatibility issues is the nice thing about that original proposal. Albeit that I'd extend/mutate my original proposal to encompass some of the further discussion it generated.

    It can easily be extended to make %{...} a generic, interpolate whatever is inside this embedded code block and convert the result to a string in the default manner.

    And that could further be extended in a manner in keeping with normal printf rules so that it can become: %fw.p{...} where the f, w & p follow the same rules for flags, width & precision as are applied to the standard s specifier.

    To simplify: %fw.p{xxx} acts pretty much like:

    printf "%fw.ps", "@{[xxx]}"

    The code xxx is evaluated, the result converted to as string, and the string substituted as if %s had been used.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      printf "%{" is legal, and prints %{. With warnings on, it does issue a warning, but it's (currently) not illegal.

      But your initial proposal talked about interpolating in strings, and in strings, "%{hash}" is currently fine. No warnings. I'd be more worried about regular strings 'breaking' than any (s)printf formats.

        As far as I know, none of the new extensions in 5.10 are enabled unless a switch or pragma is used, so old code can continue untouched.

        The point about %{} is that it is a fairly natural extension of existing mechanisms that doesn't conflict with existing uses. That there may exist by happenstance some code that would need to be changed in minor ways before it would run under the auspices of the feature pragma is not, (should not be), a barrier to the addition of new features.


        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://702883]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2014-07-13 17:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (251 votes), past polls