|< 1 2 3 >| | 24 Einträge, 3 Seiten |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
sub myCmp {
$a cmp $b;
}
sub myFunc {
my($sortFunc, @arr) = @_;
# do something ...
@arr = sort $sortFunc @arr;
# do something else ...
return(@arr);
}
@tmpArr = ( "xxx", "aaa", "zzz", "bbb" );
@tmpArr = myFunc(\&myCmp, @tmpArr);
1
2
3
4
5
6
7
sub myCmp {
$a->name() cmp $b->name();
}
@tmpArr = ( $obj_1, $obj_2, $obj_3 );
$someObj->myMethod(\&myCmp, @tmpArr);
Can't call method "name" on an undefined value at ./usTree.pl line ...
comparing '' and '' ...
Can't call method "name" on unblessed reference at ./usTree.pl line 83.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#!/usr/bin/perl
use strict;
use warnings;
my @array = 1..100;
sub backward { $b <=> $a }
mysort(\&backward);
sub mysort {
my $func = shift;
print join("\n", sort $func @array);
}
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
#!/usr/bin/perl
use strict;
use warnings;
my @array = map { A->new($_) } 1..100;
sub backward { $b->value <=> $a->value }
mysort(\&backward);
sub mysort {
my $func = shift;
print join("\n", map { $_->value } sort $func @array);
}
package A;
sub new {
my $class = shift;
my $val = shift;
return bless [$val], $class;
}
sub value {
my $class = shift;
return $class->[0];
}
1;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
sub new {
my($class) = shift;
my($name) = shift;
my($self) = {};
$self = { childs => \() };
bless($self, $class);
$self->{name} = $name;
$self->{parent} = undef;
return($self);
}
|< 1 2 3 >| | 24 Einträge, 3 Seiten |