Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

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 all is quiet...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2017-04-30 21:04 GMT
Find Nodes?
    Voting Booth?
    I'm a fool:

    Results (542 votes). Check out past polls.