line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
=head1 NAME |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
Data::FreqConvert - converts variables to scalars holfding frequencys of keys in values |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 VERSION |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
Version 0.03 |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 SYNOPSIS |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
use Data::FreqConvert; |
13
|
|
|
|
|
|
|
use Data::Printer; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
my $data = Data::FreqConvert->new(); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
my %a = ("a"=>1,"b"=>1,"c"=>1); |
18
|
|
|
|
|
|
|
my $a = {"a"=>1,"b"=>1,"c"=>1,"a"=>3}; |
19
|
|
|
|
|
|
|
my @a = ("a","b","c","a"); |
20
|
|
|
|
|
|
|
my $b = "a\nb\nc\nc"; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
my $r = $data->freq($b); |
23
|
|
|
|
|
|
|
p $r; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
$r = $data->freq(\@a); |
26
|
|
|
|
|
|
|
p $r; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
$r = $data->freq($a); |
29
|
|
|
|
|
|
|
p $r; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=cut |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
package Data::FreqConvert; |
34
|
|
|
|
|
|
|
|
35
|
2
|
|
|
2
|
|
61656
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
55
|
|
36
|
2
|
|
|
2
|
|
12
|
use warnings; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
66
|
|
37
|
|
|
|
|
|
|
|
38
|
2
|
|
|
2
|
|
1853
|
use Data::Freq; |
|
2
|
|
|
|
|
56196
|
|
|
2
|
|
|
|
|
68
|
|
39
|
2
|
|
|
2
|
|
10114
|
use Data::Dumper; |
|
2
|
|
|
|
|
28815
|
|
|
2
|
|
|
|
|
139
|
|
40
|
2
|
|
|
2
|
|
2280
|
use Data::Printer; |
|
2
|
|
|
|
|
104928
|
|
|
2
|
|
|
|
|
17
|
|
41
|
2
|
|
|
2
|
|
2151
|
use IO::Capture::Stdout; |
|
2
|
|
|
|
|
6399
|
|
|
2
|
|
|
|
|
1214
|
|
42
|
|
|
|
|
|
|
our $VERSION = "0.01"; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub new { |
45
|
1
|
|
|
1
|
0
|
1147
|
my $class = shift; |
46
|
1
|
|
|
|
|
4
|
my (%params) = @_; |
47
|
|
|
|
|
|
|
|
48
|
1
|
|
|
|
|
2
|
my $self = {}; |
49
|
1
|
|
|
|
|
3
|
bless $self, $class; |
50
|
|
|
|
|
|
|
|
51
|
1
|
|
|
|
|
3
|
return $self; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub trim { |
55
|
|
|
|
|
|
|
|
56
|
12
|
|
|
12
|
0
|
17
|
my $string = shift; |
57
|
12
|
50
|
|
|
|
23
|
$string = "" unless $string; |
58
|
12
|
|
|
|
|
22
|
$string =~ s/^\s+//; |
59
|
12
|
|
|
|
|
17
|
$string =~ s/\s+$//; |
60
|
12
|
|
|
|
|
19
|
$string =~ s/\t//; |
61
|
12
|
|
|
|
|
16
|
$string =~ s/^\s//; |
62
|
12
|
|
|
|
|
14
|
$string =~ s/^->//; |
63
|
12
|
|
|
|
|
15
|
$string =~ s/^=>//; |
64
|
12
|
|
|
|
|
23
|
return $string; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub prepArg { |
68
|
2
|
|
|
2
|
0
|
3
|
my $self = shift; |
69
|
2
|
|
|
|
|
5
|
my ($arg) = @_; |
70
|
2
|
|
|
|
|
4
|
my $ref = ref $arg; |
71
|
2
|
|
|
|
|
4
|
my @return = (); |
72
|
|
|
|
|
|
|
|
73
|
2
|
50
|
|
|
|
11
|
if($ref =~ /HASH/) { |
|
|
100
|
|
|
|
|
|
74
|
0
|
|
|
|
|
0
|
@return = keys %$arg; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
elsif($ref =~ /ARRAY/) { |
77
|
1
|
|
|
|
|
4
|
@return = @$arg; |
78
|
|
|
|
|
|
|
}else{ |
79
|
|
|
|
|
|
|
|
80
|
1
|
|
|
|
|
5
|
@return = split("\n",$arg); |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
2
|
|
|
|
|
7
|
return @return; |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub freq { |
89
|
2
|
|
|
2
|
0
|
14
|
my ($self,$arg) = @_; |
90
|
2
|
|
|
|
|
7
|
my @set = $self->prepArg($arg); |
91
|
2
|
|
|
|
|
28
|
my $data = Data::Freq->new(); |
92
|
2
|
|
|
|
|
185
|
foreach my $n( @set){ |
93
|
8
|
|
|
|
|
547
|
$data->add($n); |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
2
|
|
|
|
|
142
|
my $capture = IO::Capture::Stdout->new; |
97
|
2
|
|
|
|
|
63
|
$capture->start; |
98
|
2
|
|
|
|
|
154
|
$data->output(); |
99
|
2
|
|
|
|
|
741
|
$capture->stop(); |
100
|
|
|
|
|
|
|
|
101
|
2
|
|
|
|
|
85
|
my $ret = {}; |
102
|
2
|
|
|
|
|
12
|
my @buffer = reverse grep{/\w|\d/}$capture->read; |
|
36
|
|
|
|
|
117
|
|
103
|
|
|
|
|
|
|
|
104
|
2
|
|
|
|
|
5
|
my $last = ""; |
105
|
2
|
|
|
|
|
4
|
foreach my $z(@buffer){ |
106
|
|
|
|
|
|
|
|
107
|
12
|
|
|
|
|
24
|
$z = trim($z); |
108
|
|
|
|
|
|
|
|
109
|
12
|
100
|
|
|
|
33
|
if($z !~ m/^\d/) { |
110
|
6
|
|
|
|
|
13
|
$ret->{$z}=""; |
111
|
6
|
|
|
|
|
29
|
$last = $z; |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
else { |
115
|
6
|
|
|
|
|
12
|
$ret->{$last}=$z; |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
2
|
|
|
|
|
28
|
return $ret; |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=head1 AUTHOR |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
Mahiro Ando, C<< >> |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
Copyright 2015 Hagen Geissler |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
134
|
|
|
|
|
|
|
under the terms of either: the GNU General Public License as published |
135
|
|
|
|
|
|
|
by the Free Software Foundation; or the Artistic License. |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
See http://dev.perl.org/licenses/ for more information. |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=cut |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
1; |