in reply to Re^10: Order of evaluation/interpolation of references
in thread Order of evaluation/interpolation of references

> "The price is: $obj->tostring()\n";?

Isn't evaled for me, could you please give me a complete and working snippet?

Cheers Rolf

  • Comment on Re^11: Order of evaluation/interpolation of references

Replies are listed 'Best First'.
Re^12: Order of evaluation/interpolation of references
by BrowserUk (Patriarch) on Mar 08, 2012 at 14:19 UTC
    > "The price is: $obj->tostring()\n";? Isn't evaled for me,

    I know. But wouldn't it be convenient if it was interpolated(*)?

    See http://szabgab.com/perl-6--scalar-array-and-hash-interpolation.html

    Just expressions: say "Take 1+4";

    will print: Take 1+4

    as expected but as I wrote you can put any expression in the curly braces, so you can also write: say "Take {1+4}";

    that will print: Take 5

    Isn't that nicer than print "Take " . ( 1 + 4 ) . "\n";?

    And remember, interpolation is not like string eval, more like block eval. It can be compiled at compile time, and just run on demand.


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    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.

    The start of some sanity?

      Admittedly I'm pretty far off topic from the thread, but I prefer:

      print "Take ", 1 + 4, "\n";

      and like this even more:

      printf "Take %i\n", 1 + 4;

      But the prospect of a cleaner syntax to interpolate more... stuff than we currently can is interesting.

        That doesn't solve the problem though:
        sub X { state $x; $x = shift; \$x; } print ${X(1)}, " ", ${X(2)}, "\n"; print ${X(1)}, " "; print ${X(2)}, "\n"; printf "%d %d\n", ${X(1)}, ${X(2)}; printf "%d ", ${X(1)}; printf "%d\n", ${X(2)}; __END__ 2 2 1 2 2 2 1 2

        The curse of the trivial example. Would you agree that first is a lot easier on the eyes than the latter two?:

        print "And the set contains [ { sort @a } ]\n";; And the set contains [ brown dog fox jumps lazy over quick the the ] printf "And the set contains [ %s ]\n", join ' ', sort @a;; And the set contains [ brown dog fox jumps lazy over quick the the ] print "And the set contains [ ", join( ' ', sort @a ), " ]\n";; And the set contains [ brown dog fox jumps lazy over quick the the ]

        Even with the complication of the p5 syntax, it's still nicer to my eyes:

        print "And the set contains [ @{[ sort @a ]} ]\n";; And the set contains [ brown dog fox jumps lazy over quick the the ]

        With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
        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.

        The start of some sanity?