Debian Codegraph @

interval

raw ◀ ▶
Source reconstructed at patch state 2 of 4 — not the installed (fully patched) source.
4 Debian patches touch this file
1 #!/usr/bin/perl -w
2
3 # numinterval: This program calculates and displays the intervals between the
4 # first line and the second, between the second line and the third on
5 # through the end of the file.
6 #
7 # Copyright (C) 2002-2004 Suso Banderas
8
9 # This program is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU General Public License
11 # as published by the Free Software Foundation; either version 2
12 # of the License, or (at your option) any later version.
13 #
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
18 #
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, write to the Free Software
21 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 #
23 # You may contact the author at <[email protected]>.
24
25 #######################
26 # VARIABLES AND SETUP #
27 #######################
28
29 use Getopt::Std;
30 use strict;
31 use vars qw/ %opts $verbose /;
32
33 getopts('hdVq', \%opts);
34
35 my ($file, @number_array,$interval, $number);
36
37 if ($opts{'h'}) {
38 &help();
39 exit(0);
40 }
41
42 if ($opts{'d'}) {
43 $verbose = 3;
44 print STDERR "Debug mode\n";
45 } elsif ($opts{'V'}) {
46 $verbose = 2;
47 print STDERR "Verbose mode\n";
48 } elsif ($opts{'q'}) {
49 $verbose = 0; # Nothing except the final answer
50 } else {
51 $verbose = 1; # Normal warnings and such.
52 }
53
54
55 ################
56 # MAIN PROGRAM #
57 ################
58
59 # For file args
60 if (@ARGV) {
61 foreach $file (@ARGV) {
62 print STDERR "Reading from file $file.\n" if ($verbose >= 2);
63 open (ARGFILE, "$file") &&
64 process_filehandle(\*ARGFILE, \@number_array) ||
65 $verbose && warn "Couldn't open file $file for reading: $!\n";
66 close (ARGFILE);
67 }
68 # For STDIN
69 } else {
70 print STDERR "Reading from STDIN.\n" if ($verbose >= 2);
71 process_filehandle(\*STDIN, \@number_array);
72 }
73
74 my $lastnumber;
75 foreach $number (@number_array) {
76 if (defined($lastnumber)) {
77 $interval = $number - $lastnumber;
78 print "$interval\n";
79 }
80 $lastnumber = $number;
81 }
82
83 exit(0);
84
85 ###############
86 # SUBROUTINES #
87 ###############
88
89 sub help {
90 print <<"EOF";
91 -----------------------------------------------------------------------
92 numinterval : Calculate the numeric intervals between lines in input.
93 -----------------------------------------------------------------------
94 Usage:
95
96 template [options] <file>
97 | template [options]
98 template [options]
99
100 Options:
101 -q Don't print any warnings.
102 -d Debug. For developers only.
103 -V Increase verbosity.
104 -h Help: You're looking at it.
105 EOF
106 }
107
108 sub process_filehandle {
109 my $filehandle = shift;
110 my $number_array_ref = shift;
111
112 while (<$filehandle>) {
113 if (m/^\s*(\-?[0-9]*\.?[0-9]+)/) {
114 print STDERR "found number: $1\n" if ($verbose >= 3);
115 push(@$number_array_ref, $1);
116 }
117 }
118 return 1;
119 }
120
121
122 # Lay down some of that perl pod action.
123 =pod
124
125 =head1 NAME
126
127 numinterval - Show the numeric intervals between each line in a file.
128
129 =head1 SYNOPSIS
130
131 B<numinterval> [-dhV] <FILE>
132
133 | B<numinterval> [-dhV] (Input on STDIN from pipeline.)
134
135 B<numinterval> [-dhV] (Input on STDIN. Use Ctrl-D to stop.)
136
137 =head1 DESCRIPTION
138
139 B<numinterval>
140 will calculate and display the numeric interval between one number and the
141 next on an input stream.
142
143 This can be quite useful for showing quantities of increase or decrease
144 of data when the numbers themselves aren't providing you with what you want.
145 For instance, I wrote this program after wanting to see the rate of change
146 in box office ticket sales for movies on imdb.com. ;-)
147
148 =head1 OPTIONS
149
150 -h Help: You're looking at it.
151 -V Increase verbosity.
152 -d Debug mode. For developers
153 -q Don't print any warnings. Quiet mode.
154
155
156 =head1 SEE ALSO
157
158 numaverage(1), numbound(1), numnormalize(1), numgrep(1), numprocess(1), numsum(1), numrandom(1), numrange(1), numround(1)
159
160 =head1 COPYRIGHT
161
162 numinterval is part of the num-utils package, which is copyrighted by
163 Suso Banderas and released under the GPL license. Please read
164 the COPYING and LICENSE files that came with the num-utils package
165
166 Developers can read the GOALS file and contact me about providing
167 submitions or help for the project.
168
169 =head1 MORE INFO
170
171 More info on numinterval can be found at:
172
173 =over 1
174
175 =item B<http://suso.suso.org/programs/num-utils/>
176
177 =back
178
179 =cut
180