List Info

Thread: Re: localising hash element by variable




Re: localising hash element by variable
user name
2007-05-30 07:21:15
"Rafael Garcia-Suarez" <rgarciasuarezgmail.com> wrote:
:On 28/05/07, Bo Lindbergh <blglhagernas.com> wrote:
:> 28 maj 2007 kl. 11.51 skrev Rafael Garcia-Suarez:
:> > Your patch looks correct. Could you provide a
patch to a test file
:> > as well?
:>
:> Can do.  t/op/local.t seems to be the logical choice.
:
:Thanks, applied as #31301.

While the implementing code does not distinguish, I'd like
to add another
test for completeness: conceptually, the version with a
lexical element
carries an association with closures that we don't have for
a dynamic one.

Hugo
--- t/op/local.t.old	2007-05-29 09:44:17.000000000 +0100
+++ t/op/local.t	2007-05-30 13:02:51.000000000 +0100
 -5,7
+5,7 
     INC = qw(. ../lib);
     require './test.pl';
 }
-plan tests => 117;
+plan tests => 120;
 
 my $list_assignment_supported = 1;
 
 -442,4
+442,15 
     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);
+}

[1]

about | contact  Other archives ( Real Estate discussion Medical topics )