From: Gurusamy Sarathy Date: Wed, 4 Sep 1996 02:54:56 +0000 (+0000) Subject: Re: \ ( @array ) busted for lexical @array (once more) X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=58e0a6aef843ff1011481f826c2a83b86bc9e67a;p=p5sagit%2Fp5-mst-13.2.git Re: \ ( @array ) busted for lexical @array (once more) --- diff --git a/op.c b/op.c index 9ee7e29..b992fde 100644 --- a/op.c +++ b/op.c @@ -997,6 +997,8 @@ I32 type; case OP_PADAV: case OP_PADHV: modcount = 10000; + if (type == OP_REFGEN && op->op_flags & OPf_PARENS) + return op; /* Treat \(@foo) like ordinary list. */ /* FALL THROUGH */ case OP_PADSV: modcount++; diff --git a/pod/perlref.pod b/pod/perlref.pod index dc10eed..53e9f7d 100644 --- a/pod/perlref.pod +++ b/pod/perlref.pod @@ -73,8 +73,11 @@ Note that taking a reference to an enumerated list is not the same as using square brackets--instead it's the same as creating a list of references! - @list = (\$a, \$b, \$c); - @list = \($a, $b, $c); # same thing! + @list = (\$a, \@b, \%c); + @list = \($a, @b, %c); # same thing! + +As a special case, C<\(@foo)> returns a list of references to the contents +of C<@foo>, not a reference to C<@foo> itself. Likewise for C<%foo>. =item 3. diff --git a/t/op/ref.t b/t/op/ref.t index 38e34f0..0787295 100755 --- a/t/op/ref.t +++ b/t/op/ref.t @@ -1,6 +1,6 @@ #!./perl -print "1..41\n"; +print "1..47\n"; # Test glob operations. @@ -189,12 +189,30 @@ sub foo { print $_[1] } package WHATEVER; foo WHATEVER "ok 38\n"; +# +# test the \(@foo) construct +# +package main; +@foo = (1,2,3); +@bar = \(@foo); +@baz = \(1,@foo,@bar); +print @bar == 3 ? "ok 39\n" : "not ok 39\n"; +print grep(ref($_), @bar) == 3 ? "ok 40\n" : "not ok 40\n"; +print @baz == 3 ? "ok 41\n" : "not ok 41\n"; + +my(@fuu) = (1,2,3); +my(@baa) = \(@fuu); +my(@bzz) = \(1,@fuu,@baa); +print @baa == 3 ? "ok 42\n" : "not ok 42\n"; +print grep(ref($_), @baa) == 3 ? "ok 43\n" : "not ok 43\n"; +print @bzz == 3 ? "ok 44\n" : "not ok 44\n"; + package FINALE; { - $ref3 = bless ["ok 41\n"]; # package destruction - my $ref2 = bless ["ok 40\n"]; # lexical destruction - local $ref1 = bless ["ok 39\n"]; # dynamic destruction + $ref3 = bless ["ok 47\n"]; # package destruction + my $ref2 = bless ["ok 46\n"]; # lexical destruction + local $ref1 = bless ["ok 45\n"]; # dynamic destruction 1; # flush any temp values on stack }