On Fri, Jul 16, 2010 at 06:15, Rob Coops <rco...@gmail.com> wrote:
snip
> Yes it is the same but for readability reasons is better to use the @{}
> solution. Think about a complex structure you could get something like
> @%$variable which looks more like you are cursing cartoon style
> then writing code certainly if the data structure gets a little more complex
> then that.
snip

No you won't.  %...@$varname is not valid Perl 5, it isn't even valid
Perl 6.  The only thing that can ever be dereferenced is a scalar
value.  So it can get bad:

my $ref = \\\\\\[1];
print @$$$$$$$ref, "\n";

but I fail to see how

print @{${${${${${${$ref}}}}}}}, "\n";

or even worse

print @{ ${ ${ ${ ${ ${ ${ $ref } } } } } } }, "\n";

makes that any better.  The purpose of ${}, @{}, and %{} is to handle
cases where just @ or % would not do what you mean.  For instance,

my @a = ([5]);
my $x = $$a[0];   #bad, doesn't do what you mean
my $y = ${$a[0]}; #good

This is one of the places I disagree with [Perl Best Practices][0] and
consequently [Perl::Critic][1] (although you have to turn it up to
brutal to get it to complain).

The better rule is to use braces when dealing with an expresion that
is more complex than just a variable name.

 [0]: http://oreilly.com/catalog/9780596001735
 [1]: http://search.cpan.org/dist/Perl-Critic/lib/Perl/Critic.pm

-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to