Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

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 => 'juerd.nl', plp_site => 'plp.juerd.nl', do_not_use => 'spamtrap' }


Comment on Re: Perl Idioms Explained - ${\$obj->method} and @{[sort @list]}
Select or Download Code
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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (7)
As of 2015-07-05 20:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (68 votes), past polls