diff options
author | Ilya Zakharevich <ilya@math.berkeley.edu> | 1998-10-27 20:20:33 -0500 |
---|---|---|
committer | Gurusamy Sarathy <gsar@cpan.org> | 1998-10-28 22:02:30 +0000 |
commit | d0ecd44c5964f10ab34d28eea63e112aa8c61503 (patch) | |
tree | ee081e2e55d792df7b7592fd047d5023c41064ee /t/pragma | |
parent | 6071deed1123166fa8c7c5412c9f7b669e8f7139 (diff) | |
download | perl-d0ecd44c5964f10ab34d28eea63e112aa8c61503.tar.gz |
Make sort respect overloading
Message-Id: <199810280620.BAA06893@monk.mps.ohio-state.edu>
p4raw-id: //depot/perl@2117
Diffstat (limited to 't/pragma')
-rwxr-xr-x | t/pragma/overload.t | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/t/pragma/overload.t b/t/pragma/overload.t index afba8a3221..0682266ab4 100755 --- a/t/pragma/overload.t +++ b/t/pragma/overload.t @@ -694,5 +694,17 @@ test($c, "bareword"); # 135 test( scalar ($seven =~ /i/), '1') } +{ + package sorting; + use overload 'cmp' => \∁ + sub new { my ($p, $v) = @_; bless \$v, $p } + sub comp { my ($x,$y) = @_; ($$x * 3 % 10) <=> ($$y * 3 % 10) or $$x cmp $$y } +} +{ + my @arr = map sorting->new($_), 0..12; + my @sorted1 = sort @arr; + my @sorted2 = map $$_, @sorted1; + test "@sorted2", '0 10 7 4 1 11 8 5 12 2 9 6 3'; +} # Last test is: -sub last {173} +sub last {174} |