develooper Front page | perl.perl5.porters | Postings from July 2001

[PATCH B::Deparse] hash key auto-quoting

Thread Next
Robin Houston
July 2, 2001 15:02
[PATCH B::Deparse] hash key auto-quoting
Message ID:
B::Deparse would incorrectly deparse code like C<$hash{warn()}> or
C<$hash{+warn}> as C<$hash{warn}>, which isn't the same thing at all.
The patch below should fix this problem.

Thanks to Richard Soderberg for telling me about this problem.


PS. I hope the patch isn't mangled by this mailer. Does anyone have
     a port of mutt to darwin?

--- ext/B/B/	Mon Jul  2 21:34:06 2001
+++ ext/B/B/	Mon Jul  2 21:49:08 2001
@@ -2668,6 +2668,16 @@
      # expression would be parenthesized as well.]
      $idx =~ s/^\((.*)\)$/$1/ if $self->{'parens'};
+    # Hash-element braces will autoquote a bareword inside themselves.
+    # We need to make sure that C<$hash{warn()}> doesn't come out as
+    # C<$hash{warn}>, which has a quite different meaning. Currently
+    # B::Deparse will always quote strings, even if the string was a
+    # bareword in the original (i.e. the OPpCONST_BARE flag is ignored
+    # for constant strings.) So we can cheat slightly here - if we see
+    # a bareword, we know that it is supposed to be a function call.
+    #
+    $idx =~ s/^([A-Za-z_]\w*)$/$1()/;

      return "\$" . $array . $left . $idx . $right;

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About