Beefy Boxes and Bandwidth Generously Provided by pair Networks Cowboy Neal with Hat
"be consistent"
 
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 rifling through the Monastery: (10)
As of 2014-04-17 10:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (444 votes), past polls