> in hindsight it would be safer if B::Deparse was grouping complex LHS of the arrow OP into parens.

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.