here a possible patch to do this. It introduces a call to a new routine maybe_parens_lhs_arrow() into the return statement of elem().
Complex LHS-> is determined by not starting with a sigil or paren.
sub elem { my $self = shift; my ($op, $cx, $left, $right, $padname) = @_; my($array, $idx) = ($op->first, $op->first->sibling); $idx = $self->elem_or_slice_single_index($idx); unless ($array->name eq $padname) { # Maybe this has been fixed + $array = $array->first; # skip rv2av (or ex-rv2av in _53+) } if (my $array_name=$self->elem_or_slice_array_name ($array, $left, $padname, 1)) { return "\$" . $array_name . $left . $idx . $right; } else { # $x[20][3]{hi} or expr->[20] my $arrow = is_subscriptable($array) ? "" : "->"; return maybe_parens_lhs_arrow($self->deparse($array, 24), $arrow) . $left . $idx . $right; } } sub maybe_parens_lhs_arrow { my ($lhs, $arrow) = @_; return "($lhs)$arrow" if ($arrow eq "->" and $lhs !~ /^[$@%&(*]/); return "$lhs$arrow"; }
Looks like a weird hack ... much like most of B::Deparse ! :)
That's teh result then:
$ perl -I. -MO=Deparse -e '(do $foo)->{$bar}' (do($foo))->{$bar}; -e syntax OK $ perl -I. -MO=Deparse -e '$foo->{$bar}' $$foo{$bar}; -e syntax OK
Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
In reply to Re^3: B::Deparse weirdness (possible patch)
by LanX
in thread B::Deparse weirdness
by choroba
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |