Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Re: Perl Idioms Explained - ${\$obj->method} and @{[sort @list]}

by Juerd (Abbot)
on Aug 21, 2003 at 16:31 UTC ( #285513=note: print w/replies, xml ) Need Help??

in reply to Perl Idioms Explained - ${\$obj->method} and @{[sort @list]}

It's important to know that simple string concatenation is more efficient, and often much easier to read.

"method result - ${ \$obj->method }\n"; "method result - " . $obj->method . "\n";
An explicit join on space or $" is more efficient than using @{[]}.
"foo @{[ some_list() ]}."; "foo ${\ join $", some_list() }"; "foo ${\ join ' ', some_list() }"; "foo " . join ' ', some_list();
Easiest to read imho is (s)printf.
printf "method result - %s\n", $obj->method;

The idiom is also explained in perlfaq4's How do I expand function calls in a string?.

Juerd # { site => '', plp_site => '', do_not_use => 'spamtrap' }

Replies are listed 'Best First'.
Re (2): Perl Idioms Explained - ${\$obj->method} and @{[sort @list]}
by VSarkiss (Monsignor) on Aug 21, 2003 at 17:57 UTC

    I agree strongly. While broquaint's writeup is valuable in explaining these idioms, I don't think it's meant to encourage their use. You've demonstrated several simpler (and better imho) alternatives.

Re^2: Perl Idioms Explained - ${\$obj->method} and @{[sort @list]}
by Aristotle (Chancellor) on Aug 24, 2003 at 07:40 UTC
    Agreed. There is just one occasion where I really like having this idiom handy: here docs. Stuffing a map (or two, or three) inside a heredoc by way of this idiom is a neat poor man's templating engine.

    Makeshifts last the longest.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (6)
As of 2020-11-28 17:24 GMT
Find Nodes?
    Voting Booth?

    No recent polls found