From 6cee328eb74e2e3a6f30d2fc2f5d3bd30f84763a Mon Sep 17 00:00:00 2001 From: Father Chrysostomos Date: Fri, 16 Dec 2011 20:46:35 -0800 Subject: [PATCH] Remove use of local($_) from dumpvar.pl I know we should really be fixing local($_), but that code in scope.c is rather twisted, and I want to see this fix in 5.16. --- lib/dumpvar.pl | 11 +++++++---- lib/dumpvar.t | 13 +++++++++++++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/lib/dumpvar.pl b/lib/dumpvar.pl index 91ec407..7aadba1 100644 --- a/lib/dumpvar.pl +++ b/lib/dumpvar.pl @@ -37,7 +37,7 @@ sub main::dumpValue { # This one is good for variable names: sub unctrl { - local($_) = @_; + for (my($dummy) = shift) { local($v) ; return \$_ if ref \$_ eq "GLOB"; @@ -47,7 +47,8 @@ sub unctrl { } else { s/([\001-\037\177])/'^'.pack('c',ord($1)^64)/eg; } - $_; + return $_; + } } sub uniescape { @@ -57,7 +58,8 @@ sub uniescape { } sub stringify { - local($_,$noticks) = @_; + (my $__, local $noticks) = @_; + for ($__) { local($v) ; my $tick = $tick; @@ -101,9 +103,10 @@ sub stringify { } $_ = uniescape($_); s/([\200-\377])/'\\'.sprintf('%3o',ord($1))/eg if $quoteHighBit; - ($noticks || /^\d+(\.\d*)?\Z/) + return ($noticks || /^\d+(\.\d*)?\Z/) ? $_ : $tick . $_ . $tick; + } } # Ensure a resulting \ is escaped to be \\ diff --git a/lib/dumpvar.t b/lib/dumpvar.t index 69ec3b2..f4f55d9 100644 --- a/lib/dumpvar.t +++ b/lib/dumpvar.t @@ -49,6 +49,11 @@ sub new { my $class = shift; bless [ @_ ], $class } use overload '""' => sub { "Bar<@{$_[0]}>" }; +package Tyre; + +sub TIESCALAR{bless[]} +# other methods intentionally omitted + package main; my $foo = Foo->new(1..5); @@ -318,3 +323,11 @@ EXPECT dumpvalue(bless[1,2,3,4],"a=b=c"); EXPECT /0 a=b=c=ARRAY\(0x[0-9a-f]+\)\n 0 1\n 1 2\n 2 3\n 3 4\n/i +######## +local *_; tie $_, 'Tyre'; stringify(''); +EXPECT +'' +######## +local *_; tie $_, 'Tyre'; unctrl('abc'); +EXPECT +abc -- 2.7.4