summaryrefslogtreecommitdiff
path: root/t
diff options
context:
space:
mode:
authorFather Chrysostomos <sprout@cpan.org>2013-06-26 00:32:58 -0700
committerFather Chrysostomos <sprout@cpan.org>2013-06-26 01:12:11 -0700
commitf65493df1c26b49c6e7c2d339c58c48f4326f4b4 (patch)
tree80ac253131eb2a0f1d2d46643b0709bd74cce033 /t
parent20d5dc239d1bc8440adfec25faf617e0e444f64e (diff)
downloadperl-f65493df1c26b49c6e7c2d339c58c48f4326f4b4.tar.gz
Put sort arguments in lvalue context
Since $a and $b are aliased to the actual scalars being sorted, and since they can be modified, the list of items needs to be in lvalue context, like the arguments to grep. Otherwise implementation details leak through, in that sort{$a=1} $_,... will modify $_, but sort{$a=1} $#_,... will fail to modify $#_. The way I have written the loop and if() condition (the if inside the loop) may seem odd and inefficient, but the next commit will take advantage of that.
Diffstat (limited to 't')
-rw-r--r--t/op/sort.t6
1 files changed, 5 insertions, 1 deletions
diff --git a/t/op/sort.t b/t/op/sort.t
index 452a66baf7..e483766ba1 100644
--- a/t/op/sort.t
+++ b/t/op/sort.t
@@ -6,7 +6,7 @@ BEGIN {
require 'test.pl';
}
use warnings;
-plan( tests => 178 );
+plan( tests => 179 );
# these shouldn't hang
{
@@ -1001,3 +1001,7 @@ sub yarn($$) { "no thinking aloud" }
eval { eval { use warnings FATAL => 'all'; () = sort yarn 1,2 } };
is $@, "",
'no panic/crash with fatal warnings when sort sub($$) returns string';
+
+$#a = -1;
+() = [sort { $a = 10; $b = 10; 0 } $#a, $#a];
+is $#a, 10, 'sort block modifying $a and $b';