forked from pjcj/Devel--Cover
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sort
56 lines (41 loc) · 676 Bytes
/
sort
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/perl -w
use strict;
my %sort =
(
B => \&backwards,
F => \&forwards
);
sub backwards
{
return $b cmp $a;
}
sub forwards
{
return $a cmp $b;
}
sub GetAlgorithm
{
my ($alg) = @_;
return $sort{$alg};
}
my @list = qw( a d e c g );
# my $alg = GetAlgorithm(('B', 'F')[int(rand(2))]);
my $alg = GetAlgorithm(('B', 'F')[0]);
@list = sort {&{$alg}} @list;
use Data::Dumper;
print STDERR Dumper(\@list);
package Failure;
sub fail
{
my @x = 1 .. 5;
my @y = sort { Failure->xyz( $a, $b ) } @x;
}
sub xyz
{
my $self = shift;
my ($a, $b) = @_;
$a <=> $b;
}
package main;
my @l = Failure->fail;
print STDERR Dumper(\@l);