line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
1
|
|
|
1
|
|
959
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
25
|
|
2
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
39
|
|
3
|
|
|
|
|
|
|
package App::FilterUtils::hz; |
4
|
|
|
|
|
|
|
# ABSTRACT: Convert frequency to cycle period |
5
|
|
|
|
|
|
|
our $VERSION = '0.001'; # VERSION |
6
|
1
|
|
|
1
|
|
5
|
use base 'App::Cmd::Simple'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
81
|
|
7
|
1
|
|
|
1
|
|
5
|
use utf8; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
8
|
|
8
|
1
|
|
|
1
|
|
20
|
use charnames qw(); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
14
|
|
9
|
1
|
|
|
1
|
|
8
|
use open qw( :encoding(UTF-8) :std ); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
4
|
|
10
|
1
|
|
|
1
|
|
216
|
use Module::Load qw(load); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
5
|
|
11
|
1
|
|
|
1
|
|
52
|
use Getopt::Long::Descriptive; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
12
|
|
|
|
|
|
|
|
13
|
1
|
|
|
1
|
|
304
|
use utf8; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
3
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=pod |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=encoding utf8 |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 NAME |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
hz - Convert frequency to cycle period |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head1 SYNOPSIS |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
$ hz 10000 |
26
|
|
|
|
|
|
|
100us |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=head1 OPTIONS |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=head2 version / v |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
Shows the current version number |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
$ hz --version |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=head2 help / h |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
Shows a brief help message |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
$ hz --help |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=cut |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub opt_spec { |
45
|
|
|
|
|
|
|
return ( |
46
|
0
|
|
|
0
|
1
|
|
[ 'version|v' => "show version number" ], |
47
|
|
|
|
|
|
|
[ 'help|h' => "display a usage message" ], |
48
|
|
|
|
|
|
|
); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub validate_args { |
52
|
0
|
|
|
0
|
1
|
|
my ($self, $opt, $args) = @_; |
53
|
|
|
|
|
|
|
|
54
|
0
|
0
|
|
|
|
|
if ($opt->{'help'}) { |
|
|
0
|
|
|
|
|
|
55
|
0
|
|
|
|
|
|
my ($opt, $usage) = describe_options( |
56
|
|
|
|
|
|
|
$self->usage_desc(), |
57
|
|
|
|
|
|
|
$self->opt_spec(), |
58
|
|
|
|
|
|
|
); |
59
|
0
|
|
|
|
|
|
print $usage; |
60
|
0
|
|
|
|
|
|
print "\n"; |
61
|
0
|
|
|
|
|
|
print "For more detailed help see 'perldoc App::FilterUtils::hz'\n"; |
62
|
|
|
|
|
|
|
|
63
|
0
|
|
|
|
|
|
print "\n"; |
64
|
0
|
|
|
|
|
|
exit; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
elsif ($opt->{'version'}) { |
67
|
0
|
|
|
|
|
|
print $App::FilterUtils::hz::VERSION, "\n"; |
68
|
0
|
|
|
|
|
|
exit; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
return; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub execute { |
75
|
0
|
|
|
0
|
1
|
|
my ($self, $opt, $args) = @_; |
76
|
|
|
|
|
|
|
|
77
|
0
|
|
|
|
|
|
$_ = $0; |
78
|
0
|
0
|
|
|
|
|
my $mult = /khz/ ? 1e3 |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
79
|
|
|
|
|
|
|
: /mhz/ ? 1e6 |
80
|
|
|
|
|
|
|
: /ghz/ ? 1e9 |
81
|
|
|
|
|
|
|
: /thz/ ? 1e12 |
82
|
|
|
|
|
|
|
: 1; |
83
|
|
|
|
|
|
|
|
84
|
0
|
0
|
|
0
|
|
|
my $readarg = @$args ? sub { shift @$args } : sub { }; |
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
|
|
|
|
85
|
0
|
|
|
|
|
|
while (defined ($_ = $readarg->())) { |
86
|
0
|
|
|
|
|
|
chomp; |
87
|
0
|
|
|
|
|
|
print fmt(1 / ($mult*$_)), "s\n"; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
0
|
|
|
|
|
|
return; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub fmt { |
94
|
0
|
|
|
0
|
0
|
|
my $s= shift; |
95
|
0
|
0
|
|
|
|
|
if ($s < 1e-12) { $s *= 1e15; $s .= 'f'; } |
|
0
|
0
|
|
|
|
|
|
|
0
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
96
|
0
|
|
|
|
|
|
elsif ($s < 1e-9) { $s *= 1e12; $s .= 'p'; } |
|
0
|
|
|
|
|
|
|
97
|
0
|
|
|
|
|
|
elsif ($s < 1e-6) { $s *= 1e9; $s .= 'n'; } |
|
0
|
|
|
|
|
|
|
98
|
0
|
|
|
|
|
|
elsif ($s < 1e-3) { $s *= 1e6; $s .= 'u'; } |
|
0
|
|
|
|
|
|
|
99
|
0
|
|
|
|
|
|
elsif ($s < 1) { $s *= 1e3; $s .= 'm'; } |
|
0
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
101
|
0
|
|
|
|
|
|
return $s; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
1; |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
__END__ |