From: Hugo van der Sanden Date: Tue, 18 Feb 1997 11:05:59 +0000 (+0000) Subject: Add test for grep() and wantarray X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=d53f8f1cc3de155a009198bbc7c01e2741aa70ac;p=p5sagit%2Fp5-mst-13.2.git Add test for grep() and wantarray Subject: Re: subscript when wantarray In <199702172207.RAA20755@rio.atlantic.net>, Chip Salzenberg writes: :First, here's a patch that makes the first case print "2" [...] :Second, the reason that it prints "2" instead of "3" is that :C<(undef)[0]> evaluates to the empty list in an array context, :but to C in a scalar context. This is on purpose. Yep, I expected that. Patch worked fine here; below is an extra test using the same code as my original example. p5p-msgid: <199702181105.LAA17895@tyree.iii.co.uk> --- diff --git a/t/op/misc.t b/t/op/misc.t index 5e628ad..d7a62dc 100755 --- a/t/op/misc.t +++ b/t/op/misc.t @@ -259,6 +259,13 @@ print p::func()->groovy(), "\n" EXPECT really groovy ######## +@list = ([ 'one', 1 ], [ 'two', 2 ]); +sub func { $num = shift; (grep $_->[1] == $num, @list)[0] } +print scalar(map &func($_), 1 .. 3), " ", + scalar(map scalar &func($_), 1 .. 3), "\n"; +EXPECT +2 3 +######## ($k, $s) = qw(x 0); @{$h{$k}} = qw(1 2 4); for (@{$h{$k}}) { $s += $_; delete $h{$k} if ($_ == 2) }