hash key auto-quoting
authorRobin Houston <robin@cpan.org>
Mon, 2 Jul 2001 23:00:48 +0000 (00:00 +0100)
committerJarkko Hietaniemi <jhi@iki.fi>
Mon, 2 Jul 2001 22:25:03 +0000 (22:25 +0000)
Message-Id: <E15HBmR-0006mc-00.2001-07-02-23-02-55@mail18.svr.pol.co.uk>

p4raw-id: //depot/perl@11109

ext/B/B/Deparse.pm

index e9426ce..2e0921f 100644 (file)
@@ -2669,6 +2669,16 @@ sub elem {
     #
     $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;
 }