Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

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

by duff (Vicar)
on Aug 21, 2007 at 14:23 UTC ( #634094=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?

Forget that ... what would be really nice would be the ability to interpolate *anything* into a string. As in Perl 6:

print "Hello, my name is {some_expression_generating_name();} and I'm +here to help.";
Sure, it makes the curly braces special, but that's a small price to pay compared to the benefit IMHO.


Comment on Re^2: what would you like to see in perl5.12?
Download Code
Re^3: what would you like to see in perl5.12?
by BrowserUk (Pope) on Aug 21, 2007 at 15:28 UTC

    Actually yes. That would solve this problem, and several other similar ones.

    Given that whatever was put in place would have to remain notionally backwards compatible--which probably means any new interpolation mechanism is a non-starter but---I'd probably go with:

    "some stuff {{ any perl expression here }} more stuff"

    Indeed, if I'd been spec'ing Perl 6 interpolation, I think I would have removed all other interpolations in favour of a single 'interpret the block and substitute whatever it produces in its place' construct.

    It mildly complicates the simple case " xxx{{ $var }}xxx" instead of "xxx${var}xxx", but in the general case, it would be no more complicated than "xxx@ary[]xxx" or "xxx%hash{}xxx", and the consistancy would greatly simplify the parser.

    Indeed, the parsing would become simple enough that most editor syntax highligher parsers would probably be able to pick out embedded interpolation blocks, making them stand out from the surrounding string, and even highlight the embedded code in the usual manner.

    For me, the ability to have my editor highlight interpolations, (without resorting to running a second OS as an editor:), would more than make up for the slightly less convenient syntax it would require for the simple case.


    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.
      Indeed, if I'd been spec'ing Perl 6 interpolation, I think I would have removed all other interpolations in favour of a single 'interpret the block and substitute whatever it produces in its place' construct.

      Oh no! Perl 6's new quoting mechanism, with everything based on a single C<Q> and a bunch of adverbs is just breathtaking: it is at same time simple, intuitive and powerful as familiar constructs like C<q> and C<qq> will remain very much the same as in Perl 5 and a terrible amount of more flexibility will be available at the tiny expense of appending a semicolon and a few letters. Or in some cases no colon at all and a single letter.

      For me, the ability to have my editor highlight interpolations, (without resorting to running a second OS as an editor:), would more than make up for the slightly less convenient syntax it would require for the simple case.

      Oh well, that's hardly a problem for me so we definitely see things from two very different perspectives. Personally, I find too much syntax highlighting to be distracting, but when I find it... ehm... desirable. (Speaking of strings, in current Perl, e.g. when the necessary evil of a string eval of a considerable amount of code is needed and then I use q{...} or qq{...}.)

      Yet it seems to me we could still have the best of both worlds: if e.g. C<qq> implies :s, :a, :h, :f, :c and :b you may still stick to only interpolate {...} expressions when you want them to be syntax highlighted, and your editor may do a good job of doing so.

      Or if you want to stay very strict, then you may get into the habit of doing:

      macro qbuk { Q:c:b }
        with everything based on a single C<Q> and a bunch of adverbs

        I don't understand what you mean by "based on a single c<Q>"?

        And I'd just point out that the adverbs could still be used with "...{{ code }}:x ...".


        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://634094]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2014-08-01 02:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (256 votes), past polls