Are there any elegant ways to dereference an array or hash besides @{} and %{}? In my opinion, the standard method gets ugly in cases like this:
@baz = @{ $foo->{ bar }->{ baz } };
I see the problem as the @ not being close enough to the variable that it is operating on. It's next to foo when it should be close to baz.
Many people work around the problem at the expense of some elegance:
$baz_ref = $foot->{ bar }->{ baz }; @baz = @$baz_ref;
Here is a fictional alternative that requires the baz array ref to be an object instead of a primitive array:
@baz = $foo->{ bar }->{ baz }->to_array();
Here is another fictional alternative that may conflict with existing valid syntax (and therefore would not be backwards compatible if implemented):
@baz = $foo->{ bar }->@{ baz };
(As a side note, is Perl 6 going to be different in this regard?)
-Dan
In reply to Elegant way to dereference an array or hash? by danb
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |