« web/cgi-bin/yatt.lib/YATT/LRXML/NodeCursor.pm
↑ Summary
web/cgi-bin/yatt.lib/YATT/Class/Configurable.pm »
| 1 | package YATT::Util::DictOrder; | ||||||||||||||||||||||||||||
| 2 | 10 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 10 | ▶ | use warnings qw(FATAL all NONFATAL misc); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 10 | ▶ | use base qw/Exporter/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 10 | our @EXPORT_OK = qw(&dict_order &dict_sort); | |||||||||||||||||||||||||||
| 7 | 10 | our @EXPORT = @EXPORT_OK; | |||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 33 | ▶ | sub dict_order { | ||||||||||||||||||||||||||
|
Subroutine
dict_order: called CC=7 SCAR=20.6
Pod
documented
| |||||||||||||||||||||||||||||
| 10 | 33 | my ($a, $b, $start) = @_; | |||||||||||||||||||||||||||
| 11 | 33 | ▶ | $start = 1 unless defined $start; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 12 | 33 | my ($result, $i) = (0); | |||||||||||||||||||||||||||
| 13 | 33 | ▶ | for ($i = $start; $i <= $#$a and $i <= $#$b; $i++) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$i <= $a->$#* and $i <= $b->$#*
MC/DC0%0/2
$i <= $a->$#* and $i <= $b->$#*
$i <= $a->$#*
$i <= $b->$#*
Truth table33%1/3
A and B
A= $i <= $a->$#*B= $i <= $b->$#*
| |||||||||||||||||||||||||||||
| 14 | 66 | ▶ | if ($a->[$i] =~ /^\d/ and $b->[$i] =~ /^\d/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$a->[$i] =~ /^\d/ and $b->[$i] =~ /^\d/
MC/DC50%1/2
$a->[$i] =~ /^\d/ and $b->[$i] =~ /^\d/
$a->[$i] =~ /^\d/
$b->[$i] =~ /^\d/
Truth table66%2/3
A and B
A= $a->[$i] =~ /^\d/B= $b->[$i] =~ /^\d/
| |||||||||||||||||||||||||||||
| 15 | 33 | $result = $a->[$i] <=> $b->[$i]; | |||||||||||||||||||||||||||
| 16 | } else { | ||||||||||||||||||||||||||||
| 17 | 33 | $result = $a->[$i] cmp $b->[$i]; | |||||||||||||||||||||||||||
| 18 | } | ||||||||||||||||||||||||||||
| 19 | 66 | ▶ | return $result unless $result == 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 20 | } | ||||||||||||||||||||||||||||
| 21 | 0 | return $#$a <=> $#$b; | |||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | # a => ['a', 'a'] | ||||||||||||||||||||||||||||
| 25 | # q1a => ['q1a', 'q', 1, 'a'] | ||||||||||||||||||||||||||||
| 26 | # q11b => ['q11b', 'q', 11, 'b'] | ||||||||||||||||||||||||||||
| 27 | 1 | ▶ | sub dict_sort (@) { | ||||||||||||||||||||||||||
|
Subroutine
dict_sort: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 28 | 1 | map {$_->[0]} sort {dict_order($a,$b)} map {[$_, split /(\d+)/]} @_; | |||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 10 | 1; | |||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | =head1 NAME | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | YATT::Util::DictOrder - Dictionary-style ordering and sorting. | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | use YATT::Util::DictOrder; | ||||||||||||||||||||||||||||
| 40 | print join ",", dict_sort qw(q3-1 q3 q10a q1); | ||||||||||||||||||||||||||||
| 41 | # prints "q1,q3,q3-1,q10a" | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | print join ",", | ||||||||||||||||||||||||||||
| 44 | map {$$_[0]} | ||||||||||||||||||||||||||||
| 45 | sort {dict_order($a, $b, 1)} | ||||||||||||||||||||||||||||
| 46 | map {[$$_[0], split /(\d+)/, $$_[1]]} | ||||||||||||||||||||||||||||
| 47 | [qw(foo q3-1)], | ||||||||||||||||||||||||||||
| 48 | [qw(summer q3)], | ||||||||||||||||||||||||||||
| 49 | [qw(moe q10a)], | ||||||||||||||||||||||||||||
| 50 | [qw(romantic q1)]; | ||||||||||||||||||||||||||||
| 51 | # prints "romantic,summer,foo,moe" | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | =head2 C<dict_sort> | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | =head2 C<dict_order> | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | KOBAYASI, Hiroaki (C<hkoba@cpan.org>) | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | =head1 LICENSE | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | This library is free software; you may redistribute it and/or modify | ||||||||||||||||||||||||||||
| 66 | it under the same terms as Perl itself. | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | =cut | ||||||||||||||||||||||||||||