I have a Perl program that loads a bunch of report names in a hash (%TITLES).
I then read through files in a directory trying to match the report name of the file
to the report name in the hash. When I get a hit, I use the reference of the hash hit
to pick up an array that tells me on what line of the report I will find certain items.
I have it working............Hooray for me :-)
But I don't like what I have to do to get it working. Here is a snippet with some
explanation to explain what is or isnot happening.
Although, I have shown the first of 2 other processing sections ( there is one for
$rptid, $edate, $rdate) I have shown only the first.
The other two are the same exact structure and only the regex and variable names are
different. It is possible that I will process through all
sections based on the flags in @values. If I have to adjust the line count to match
the flag I was just doing a <FILE>; and assumed (silly me)
that $_ would be set. I found that it wasn't so I assigned it.
Hope this is clear enough to be of some help. If not I am wearing my asbestos suit
today. :-)
Looking for a better
way..............TIA...................................................MY COMMENTS
<SNIP>
152 LINELOOP:while (<FILE>) {
read a line from FILE into $_
153 chomp;
154 if ( $linecnt == 86 ) { # if not found in 20
155 print "*********ERROR**********\n";
156 print "$file:NO_TITLE_FOUND\n";
157 print "*********ERROR**********\n\n";
158 last FILELOOP; # lines....quit!
159 } else {
160 $fname=$file;
161 ($rptname, $rcvdate, $procdate) = split(/\./, $fname);
162 $lookup = $rptname;
163 $rptname =~ tr!d_salgpqt!- \/&\<\>()\'!;
164
165 # We now have enough information to be able to start the lookup for the
information
166 # not contained in the header page of the report.
167 # We need to look up the report name in our hash table and see what lines
need to be read
168 # for the remaining parameters.
169
170 # Let's check to see if the Title is in our table. If not we need to add it
and specify
171 # the proper values. This is an error and must be corrected manually and
viprep re-run.
172
173 if (! exists $TITLES{$lookup}) {
174 print ERR "$lookup is not defined in rtitles (or BIGlist)\n";
175 print
"\n\n\n***************************************************\n\n\n";
176 print "$lookup not found in rtitles (BIGlist) table. It must
be added\n";
177 print
"\n\n\n***************************************************\n\n\n";
178 next FILELOOP;
179 }
180
181 foreach $keytitle (keys %TITLES) {
This is my foreach loop to find the Report Titles
182 if ( grep /$keytitle/, $lookup ) {
Prior to this I have check to see if the key exists.
183 @values = @{$TITLES{$keytitle}};
184 $im = $values[0];
185 $rptid = $values[1];
186 $edate = $values[3];
187 $rdate = $values[4];
188
189 # Check to see if we need to image this file.
190
191 if ($im == 0) {
192 print "LOOKUP: $lookup\n\n";
193 next FILELOOP;
194 }
195
196 # File needs to be imaged. Now check for parameters that are valid in this
report.
197 #
198 # PARM 1: Check for REPORT ID
This is 1 of right now 3 sections of code that are very similar
199 #
and this is where the ugliness that I am asking
about comes
200
201 if ($rptid == 0) {
$rptid has either a 0 (the entity doesn't exist in this
report) or
202 $rid="NO_RID";
a line #. I may have to adjust the current line number
($linecnt)
203 } else {
If I do then I have to do some reading in the file.
204 if ( $linecnt < $rptid ) {
205 until ( $linecnt == $rptid ) {
206 $_ = $look = <FILE>;
This is the ugly line. It occurs 2 more times per block. I
found
207 $linecnt++;
that if I fall through to the } else { and have to
adjust my
208 }
position in the file that doing a <FILE>; by
itself is not
209 $rid = grid($_);
resetting $_.
210 } elsif ( $linecnt > $rptid ) {
211 seek (FILE, 0, 0);
212 $linecnt=1;
213 until ($linecnt == $rptid ) {
214 $_ = $look = <FILE>;
215 $linecnt++;
216 }
217 $rid = grid($_);
218 } else {
219 $look = $_;
220 $look =~ /^\s+(\w+-?\w+)/;
221 $rid = $1;
222 # $rid = &grid($_);
223 }
224 }
</SNIP>
--
-------------------------------------------------------------------------
"They that can give up essential liberty
to obtain a little temporary safety
deserve neither liberty nor safety."
-- Benjamin Franklin
-------------------------------------------------------------------------
RRRRR Gary Luther
RR RR SAF
RR RR UTABEGAS 2500 Broadway
RR RR Helena, MT 59602
RRRR [EMAIL PROTECTED]
RR RR ULE !!
RR RR Visit our website at
RR RR http://www.safmt.org
BEGIN:VCARD
VERSION:2.1
X-GWTYPE:USER
FN:Gary Luther
TEL;WORK:0631
ORG:;Computer Center
TEL;PREF;FAX:(406) 444-0684
EMAIL;WORK;PREF;NGW:[EMAIL PROTECTED]
N:Luther;Gary
TITLE:Systems Administrator
END:VCARD