@INC = qw(. ../lib);
require './test.pl';
}
-plan tests => 114;
+plan tests => 122;
my $list_assignment_supported = 1;
eval { for("a") { for $x (1,2) { local $_="b"; s/(.*)/+$1/ } } };
is($@, "");
-# Special local() behavior for $[
-# (see RT #38207 - Useless localization of constant ($[) in getopts.pl}
+# RT #4342 Special local() behavior for $[
{
local $[ = 1;
- local $TODO = "local() not currently working correctly with \$[";
- ok(1 == $[);
- undef $TODO;
+ ok(1 == $[, 'lexcical scope of local $[');
f();
}
}
+# when localising a hash element, the key should be copied, not referenced
+
+{
+ my %h=('k1' => 111);
+ my $k='k1';
+ {
+ local $h{$k}=222;
+
+ is($h{'k1'},222);
+ $k='k2';
+ }
+ ok(! exists($h{'k2'}));
+ is($h{'k1'},111);
+}
+{
+ my %h=('k1' => 111);
+ our $k = 'k1'; # try dynamic too
+ {
+ local $h{$k}=222;
+ is($h{'k1'},222);
+ $k='k2';
+ }
+ ok(! exists($h{'k2'}));
+ is($h{'k1'},111);
+}
+
+# Keep this test last, as it can SEGV
+{
+ local *@;
+ pass("Localised *@");
+ eval {1};
+ pass("Can eval with *@ localised");
+}
+