develooper Front page | perl.perl5.porters | Postings from February 2006

Re: Change 27287: Add test for RT #2166: foreach spuriously autovivifies

Thread Next
From:
Nicholas Clark
Date:
February 23, 2006 09:53
Subject:
Re: Change 27287: Add test for RT #2166: foreach spuriously autovivifies
Message ID:
20060223175249.GN706@plum.flirble.org
On Thu, Feb 23, 2006 at 09:45:01AM -0800, Steve Peters wrote:
> Change 27287 by stevep@stevep-mccoy on 2006/02/23 17:42:09
> 
> 	Add test for RT #2166: foreach spuriously autovivifies
> 
> Affected files ...
> 
> ... //depot/perl/t/cmd/for.t#13 edit
> 
> Differences ...
> 
> ==== //depot/perl/t/cmd/for.t#13 (xtext) ====
> Index: perl/t/cmd/for.t
> --- perl/t/cmd/for.t#12~23112~	2004-07-15 02:16:43.000000000 -0700
> +++ perl/t/cmd/for.t	2006-02-23 09:42:09.000000000 -0800
> @@ -1,6 +1,6 @@
>  #!./perl
>  
> -print "1..78\n";
> +print "1..79\n";
>  
>  for ($i = 0; $i <= 10; $i++) {
>      $x[$i] = $i;
> @@ -457,3 +457,15 @@
>      $r .= $i;
>  }
>  is ($r, '1CBA', 'Reverse for array and value via map with var');
> +
> +TODO: {
> +    $test++;
> +    no warnings 'reserved';
> +    local $TODO = "RT #2166: foreach spuriously autovivifies";
> +    my %h;
> +    foreach (@h{a, b}) {}
> +    if(keys(%h)) {
> +        print "not ";
> +    }
> +    print "ok $test # TODO $TODO\n";
> +}
> End of Patch.

So, it seems, do hash slices as subroutine arguments:

$ perl -lwe 'sub foo {}; foo($h{a}, @h{"b", "c"}); print foreach keys %h'
c
b


Nicholas Clark

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About