lib/MARC/BBMARC.pm untested

filter: Statementstmt 0.0% 0 / 208 Branchbran 0.0% 0 / 50 Conditioncond 0.0% 0 / 31 MC/DCmcdc 0.0% 0 / 20 Subroutinesub 0.0% 0 / 24 Podpod 0.0% 0 / 13 totaltotal 0.0% 0 / 346 CC 26 SCAR 30.6
CC
26
Cov
0%
parse008date
72.0
getindicators
30.0
startstop_time
30.0
CRAP 21.3
1 #!perl -w
2  
3 =head2 JUNK CODE
4  
5 ####################
6 ####################
7 ###
8 ### Add below where it belongs. Also, use
9 ### in individual scripts where needed.
10 ###
11 ### #!/usr/bin/perl -w
12 ### # use strict;
13 ### # $| = 1;
14 ### # use MARC::File;
15 ###
16 ####################
17 ####################
18  
19 =cut
20  
21 package MARC::BBMARC;
22  
23 use strict;
24 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);
25  
26 require Exporter;
27 require AutoLoader;
28  
29 @ISA = qw(Exporter AutoLoader);
30 # Items to export into callers namespace by default. @EXPORT = qw();
31  
32 $VERSION = 1.08;
33  
34 =head1 NAME
35  
36 MARC::BBMARC
37  
38 =head1 SYNOPSIS
39  
40 Basic list of subs. For individual use, see the descriptions/POD-like info above each sub.
41  
42 use MARC::Field;
43 use MARC::File;
44 use MARC::BBMARC;
45 MARC::BBMARC::as_formatted2();
46 MARC::BBMARC::recas_formatted();
47 MARC::BBMARC::skipget();
48 MARC::BBMARC::getthreedigits();
49 MARC::BBMARC::getindicators();
50 MARC::BBMARC::updated_record_array();
51 MARC::BBMARC::read_controlnos();
52 MARC::BBMARC::readcodedata();
53 MARC::BBMARC::parse008date($field008string);
54 MARC::BBMARC::updated_record_hash();
55
56 =head1 DESCRIPTION
57  
58 Collection of methods and subroutines, add-ons to MARC::Record, MARC::File, MARC::Field.
59  
60 Subroutines include:
61  
62 C<as_formatted2()>, add-on to MARC::Field, which pretty-prints fields, separating subfields by tabs, rather than line breaks.
63  
64 C<recas_formatted()>, add-on to MARC::Record, which is the same as as_formatted, but uses as_formatted2() instead.
65  
66 C<skipget()>, add-on to MARC::File, which returns the next raw marc record from a file.
67  
68 C<updated_record_array()>, which creates an array of control numbers (001) from input file. Used with merge marc script. Call to initialize updated record array variable prior to entering loop. Accepts passed file name, or prompts for one.
69  
70 C<read_controlnos()>, reads file of control number and returns the control numbers (or lines of file) as an array. Accepts passed file name, or prompts for one.
71  
72 C<getthreedigits()>, prompts (without prompt) for 3 digit number, if not received, asks to try again.
73  
74 C<getindicators()>, prompts for 1st and 2nd indicator values. Parses for legitimate values.
75 Returns 2 array references:
76 \@indicators, \@indicatortypes
77 The first contains the values of the indicators.
78 The second contains the types of those indicators.
79 The first element in each is 'empty', so numbering
80 matches indicator 1 and indicator 2.
81 Indicator types: 'digit', 'blank', or 'any'.
82  
83 C<readcodedata()>, subroutine for reading data to build an array of country codes, geographic area codes, and language codes, valid and obsolete, for use in validate008 (in MARC::Errorchecks) and 043 validation (in Lintadditions (which uses its own, similar subroutine).
84  
85 C<parse008date($field008string)>, preliminary version of code to parse a 6 digit date in the form yymmdd into yyyy\tmm\tdd\t$errors. It is from validate008, and that subroutine might be (or has been?) cleaned by calling parse008date($field008string).
86  
87 C<counting_print( $number )>, prints out running count ('$number') passed in, based on constant MOD_INTERVAL (if count divides evenly).
88  
89 C<startstop_time()>, returns current time in h:m:s format. If numbers are 1 digit, then only that digit appears (may be fixed later).
90  
91 Also includes code to wrap around scripts, integrating startstop_time and counting_print, plus elapsed time.
92  
93 C<updated_record_hash()>, similar to updated_record_array(), but stores raw USMARC record indexed (keyed) by control number. This has not been fully tested, and will likely eat massive amounts of memory, especially for large files of records.
94  
95 C<as_array()>, add-on to MARC::Field, breaks field into flat array of subfield code-data pairs. Based on example #U9 of the MARC::Doc::Tutorial.
96  
97  
98 =head1 EXPORT
99  
100 None
101  
102 =head1 TO DO
103  
104 Figure out how to "use" and not have to put MARC::BBMARC before subroutine/method calls.
105  
106 Clean up readability of POD-like documentation.
107  
108 Test and cleanup updated_record_hash()
109  
110 (More to do in individual subs).
111  
112 Evaluate the usefulness of parse008date, which is now duplicated in MARC::Errorchecks.
113  
114 Verify each of the codes in the data against current lists and lists of changes. Maintain code list data when future changes occur.
115  
116 =cut
117  
118 ###################################################
119 # Link methods to MARC modules, for compatibility #
120 ###################################################
121  
122 *MARC::File::skipget = *MARC::BBMARC::skipget;
123 *MARC::Field::as_formatted2 = *MARC::BBMARC::as_formatted2;
124 *MARC::Field::as_array = *MARC::BBMARC::as_array;
125 *MARC::Record::as_formatted2 = *MARC::BBMARC::recas_formatted;
126  
127 =head2 as_formatted2()
128  
129 Returns a pretty string for printing in a MARC dump.
130 From MARC::Field.
131  
132 =cut
133  
134 sub as_formatted2() {
135  
136 use MARC::Field;
137  
138 my $self = shift;
139 ### @lines will contain tag number, indicators,
140 ### and subfield data.
141 my @lines = ();
142  
143 if ( $self->is_control_field() ) {
144 push( @lines, sprintf( "%03s %s", $self->{_tag}, $self->{_data} ) );
145 }
146 else {
147 my $hanger = sprintf( "%03s %1.1s%1.1s", $self->{_tag}, $self->{_ind1}, $self->{_ind2} );
148  
149 my @subdata = @{$self->{_subfields}};
150 while ( @subdata ) {
151 my $code = shift @subdata;
152 my $text = shift @subdata;
153  
154 ### push onto @lines each subfield, formatting each
155 ### according to the info in the sprintf call
156 ### hanger is already formatted as: %03==3 places,
157 ### pad with zeros; [space], 1 char, 1 char.
158 ### Then line is formatted exactly 6 spaces,
159 ### left justified in field; [space]; underscore for
160 ### subfield code (so can change that); one char;
161 ### then string of subfield data. (original code:
162 ### "%-6.6s _%1.1s%s")
163 ### changed to at sign for indicator (\@);
164 ### added tab between tag+indicator+code and subfield data
165  
166  
167 #changed 4-28-04 in attempt to remove extra spaces between fields
168 # if $hanger exists, it is first run, and has tag and indicators
169  
170 if ($hanger) {
171 push( @lines, sprintf( "%-6.6s \@%1.1s\t%s", $hanger, $code, $text ) );
172 $hanger = "";
173 }
174  
175 #once $hanger is undef, no need for 6 spaces between subfields
176 else {
177 push( @lines, sprintf( "%-0.0s\@%1.1s\t%s", $hanger, $code, $text ) );
178 }
179 } # while
180 }
181  
182 return join( "\t", @lines );
183  
184 } # as_formatted2()
185  
186 ##########################
187 ##########################
188 ##########################
189  
190 =head2 recas_formatted()
191  
192 Prints an entire record in human-readable form, using as_formatted2().
193 This puts each field on a single line and uses @ (at) as subfield
194 delimiter instead of _ (underscore).
195 Based on MARC::Record::as_formatted().
196  
197 =cut
198  
199 sub recas_formatted() {
200  
201 use MARC::Record;
202  
203 my $self = shift;
204
205 my @lines = ("LDR " . ($self->{_leader} || ""));
206 for my $field (@{$self->{_fields}}) {
207 push(@lines, $field->as_formatted2());
208 }
209  
210 return join("\n", @lines);
211  
212 } # recas_formatted
213  
214  
215  
216 ##########################
217 ##########################
218 ##########################
219  
220 =head2 skipget()
221  
222 Returns a raw MARC record string or undef.
223  
224 =cut
225  
226 sub skipget {
227  
228 use MARC::File;
229 my $self = shift;
230 $self->{recnum}++;
231  
232 my $rec = $self->_next();
233  
234 return $rec ? $rec : undef;
235  
236 }
237  
238 ##########################
239 ##########################
240 ##########################
241  
242 =head2 updated_record_array()
243  
244 Note: Creates an array of control numbers (001) from input file.
245 Use with merge marc script. Call to initialize updated record array variable prior to entering loop.
246 Prompts for updated record file.
247 Prints running count of records based on counting_print function. Works only with USMARC input files.
248  
249 =cut
250  
251 sub updated_record_array {
252  
253 use MARC::File::USMARC;
254 my @updatedrecarray;
255 ####################################
256 # To do: test abstracted input file call ##
257 ####################################
258 my $inputfile = shift;
259 unless ($inputfile) {
260 print ("What is the updated record file?:");
261 $inputfile = <>;
262 chomp $inputfile;
263 #remove double quotes inserted when drag-dropping from Windows
264 $inputfile =~ s/^\"(.*)\"$/$1/;
265 }
266 #initialize $decodedfile as new usmarc file object
267 my $decodedfile = MARC::File::USMARC->in( "$inputfile" );
268 my $recordno = 0;
269  
270 while ( my $record = $decodedfile->next()) {
271  
272 my $controlnumb = $record->field('001')->as_string();
273  
274 $updatedrecarray[$recordno] = $controlnumb;
275 $recordno++;
276 MARC::BBMARC::counting_print ($recordno);
277  
278 } #while
279  
280 return @updatedrecarray;
281  
282 } #updated_record_array
283  
284 ##########################
285 ##########################
286 ##########################
287  
288 =head2 read_controlnos()
289  
290 Accepts passed filename as arguement.
291 If nothing is passed, asks for file path/name.
292 Reads each line of file, and pushes it onto array, @controlnumberarray, which is returned.
293 Lines in the file should contain only control number.
294  
295 Since it does not do anything to the line it reads, this subroutine can be used to read lines from a file and store them in an array.
296  
297 To do: Modify existing scripts to clean control number, replacing spaces with underscores.
298 Regex-ify control number to be (3 char) - (8 digit) - (space).
299  
300 =cut
301  
302 sub read_controlnos {
303  
304 #get passed-in filename
305 my $controlinputfile = shift;
306 unless ($controlinputfile) {
307 print ("Where is the file of control numbers?\n");
308 print ("\(enter blank line if none\): ");
309 $controlinputfile = <>;
310 chomp $controlinputfile;
311 #remove double quotes inserted when drag-dropping from Windows
312 $controlinputfile =~ s/^\"(.*)\"$/$1/;
313 }
314 my @controlnumberarray = ();
315 #read line from file
316 ##line should contain only control number
317 if ($controlinputfile) {
318 open (CONTROLNOFILE, $controlinputfile) or die "Cannot open controlnofile, $!";
319 while (my $cnumber = <CONTROLNOFILE>) {
320 #get rid of line breaks
321 chomp $cnumber;
322 push (@controlnumberarray, $cnumber);
323 }#while
324 close $controlinputfile;
325 } #if filename was submitted
326
327 return @controlnumberarray;
328  
329 } # read_controlnos
330  
331 ##########################
332 ##########################
333 ##########################
334  
335  
336 =head2 getthreedigits()
337  
338 Looks for three digit input. Returns three digit string.
339  
340 =cut
341  
342 sub getthreedigits {
343  
344 ##################################################
345 ### Prompting is done in calling program ###
346 ### Assures that input is exactly three digits ###
347 ##################################################
348  
349 my $threedigits = <>;
350 chomp $threedigits;
351  
352 #added period as possible digit (4-28-04)
353  
354 if ($threedigits =~ /^[\d\.]{3}$/){
355 return "$threedigits";
356 }
357 else {
358 print "Try again\n";
359 getthreedigits()
360 }
361  
362 } #sub getthreedigits
363  
364 ##########################
365 ##########################
366 ##########################
367  
368 =head2 sub getindicators()
369  
370 Gets 1st and 2nd indicator values.
371 Parses for legitimate values.
372 Returns 2 array references:
373 \@indicators, \@indicatortypes
374 The first contains the values of the indicators.
375 The second contains the types of those indicators.
376 The first element in each is 'empty', so numbering
377 matches indicator 1 and indicator 2.
378 Indicator types: 'digit', 'blank', or 'any'.
379  
380 =head2 Get indicator additional info
381  
382 ##################################
383 ##################################
384 ### Synopsis/Calling procedure ###
385 ##################################
386  
387 my ($gotindicators, $gotindicatortypes) = getindicators();
388 print join ("\n", "indarray", @$gotindicators, "\n");
389 print join ("\n", "indtypes", @$gotindicatortypes, "\n");
390  
391 =cut
392  
393 ######################
394 ### Get indicators ###
395 ######################
396  
397 sub getindicators {
398  
399 my @indicators = [];
400 my @indicatortypes=[];
401 $indicators[0] = 'empty';
402 $indicatortypes[0]= 'empty';
403 print ("Enter space for blank, or a single digit, enter \'?\' for any\n");
404 print ("Enter indicators: 1st: ");
405 $indicators[1]=<>;
406 chomp $indicators[1];
407 print ("Enter indicators: 2nd: ");
408 $indicators[2]=<>;
409 chomp $indicators[2];
410  
411 for my $i (1..2) {
412  
413 if ($indicators[$i] =~ /^\d$/) {
414 $indicatortypes[$i]='digit';
415 }
416 elsif ($indicators[$i] =~ /^\s$/) {
417 $indicatortypes[$i]='blank';
418 }
419 elsif ($indicators[$i] =~ /^\?$/) {
420 $indicatortypes[$i]='any';
421 }
422 else {
423 ## digit, space, or ? not entered##
424 print ("Invalid indicator.\nPlease reenter: ");
425 $indicatortypes[$i]='bad';
426 }
427 } #for
428 if ($indicatortypes[1] eq 'bad' || $indicatortypes[2] eq 'bad') {
429 print ("You entered bad indicators. Try again\n");
430 @indicatortypes = [];
431 @indicators =[];
432 my ($gotindicators, $gotindicatortypes) = getindicators();
433 @indicators = @$gotindicators;
434 @indicatortypes = @$gotindicatortypes;
435 }
436  
437 return (\@indicators, \@indicatortypes);
438  
439 } #sub getindicators
440  
441  
442 =head2 readcodedata()
443  
444 readcodedata() -- Read Country, Geographic Area Code, Language Data
445  
446 =head2 DESCRIPTION (readcodedata())
447  
448 Subroutine for reading data to build an array of country codes, geographic area codes, and language codes, valid and obsolete, for use in validate008 (in MARC::Errorchecks) and 043 validation (in MARC::Lintadditions).
449  
450 =head2 SYNOPSIS (readcodedata())
451  
452 my @dataarray = MARC::BBMARC::readcodedata();
453 ## or
454 #MARC::BBMARC::readcodedata();
455 #my @countrycodes = split "\t", $MARC::BBMARC::dataarray[1];
456
457 my @countrycodes = split "\t", $dataarray[1];
458 my @oldcountrycodes = split "\t", $dataarray[3];
459 my @geogareacodes = split "\t", $dataarray[5];
460 my @oldgeogareacodes = split "\t", $dataarray[7];
461 my @languagecodes = split "\t", $dataarray[9];
462 my @oldlanguagecodes = split "\t", $dataarray[11];
463  
464 =head2 DATA Outline
465  
466 Data lines:
467 0: __CountryCodes__
468 1: countrycodes (tab-delimited)
469 2: __ObsoleteCountry__
470 3: oldcountrycodes (tab-delimited)
471 4: __GeogAreaCodes__
472 5: gacodes (tab-delimited)
473 6: __ObsoleteGeogAreaCodes__
474 7: oldgacodes (tab-delimited)
475 8: __LanguageCodes__
476 9: languagecodes (tab-delimited)
477 10: __LanguageCodes__
478 11: oldlanguagecodes (tab-delimited)
479  
480 =cut
481  
482  
483 #declare global @dataarray
484  
485 our @dataarray = ();
486  
487 sub readcodedata {
488  
489 # return @dataarray if it has been filled
490 if (@dataarray) {return @dataarray;}
491 # otherwise fill @dataarray
492 else {
493 #get start position so the next call can read the same data again
494 my $startdataposition = tell DATA;
495 while (my $dataline = <DATA>) {
496 chomp $dataline;
497 push @dataarray, $dataline;
498 }
499 #set the pointer back at the starting position
500 seek DATA, $startdataposition, 0;
501 return @dataarray;
502 }
503 } # readcodedata
504  
505 ##########################
506 ##########################
507 ##########################
508  
509 =head2 parse008date($field008string)
510  
511 Subroutine parse008date returns four-digit year, two-digit month, and two-digit day.
512 It requres an 008 string at least 6 bytes long.
513  
514  
515 =head2 SYNOPSIS (parse008date($field008string))
516  
517 my ($earlyyear, $earlymonth, $earlyday);
518 print ("What is the earliest create date desired (008 date, in yymmdd)? ");
519 while (my $earlydate = <>) {
520 chomp $earlydate;
521 my $field008 = $earlydate;
522 my $yyyymmdderr = MARC::BBMARC::parse008date($field008);
523 my @parsed008date = split "\t", $yyyymmdderr;
524 $earlyyear = shift @parsed008date;
525 $earlymonth = shift @parsed008date;
526 $earlyday = shift @parsed008date;
527 my $errors = join "\t", @parsed008date;
528 if ($errors) {
529 if ($errors =~ /is too short/) {
530 print "Please enter a longer date, $errors\nEnter date (yymmdd): ";
531 }
532 else {print "$errors\nEnter valid date (yymmdd): ";}
533 } #if errors
534 else {last;}
535 }
536  
537 =cut
538  
539 sub parse008date {
540  
541 my $field008 = shift;
542 if (length ($field008) < 6) { return "\t\t\t$field008 is too short";}
543  
544 my $hasbadchars = "";
545 my $dateentered = substr($field008,0,6);
546 my $yearentered = substr($dateentered, 0, 2);
547 #validate year portion--change dates to reflect local implementation of code
548 #(and for future use--after 2006)
549 #year created less than 06 considered 200x
550 if ($yearentered <= 6) {$yearentered += 2000;}
551 #year created between 80 and 99 considered 19xx
552 elsif ((80 <= $yearentered) && ($yearentered <= 99)) {$yearentered += 1900;}
553 else {$hasbadchars .= "Year entered is after 2006 or before 1980\t";}
554  
555 #validate month portion
556 my $monthentered = substr($dateentered, 2, 2);
557 if (($monthentered < 1) || ($monthentered > 12)) {$hasbadchars .= "Month entered is greater than 12 or is 00\t";}
558  
559 #validate day portion
560 my $dayentered = substr($dateentered, 4, 2);
561  
562 if (($monthentered =~ /^01$|^03$|^05$|^07$|^08$|^10$|^12$/) && (($dayentered < 1) || ($dayentered > 31))) {$hasbadchars .= "Day entered is greater than 31 or is 00\t";}
563 elsif (($monthentered =~ /^04$|^06$|^09$|^11$/) && (($dayentered < 1) || ($dayentered > 30))) {$hasbadchars .= "Day entered is greater than 30 or is 00\t";}
564 elsif (($monthentered =~ /^02$/) && (($dayentered < 1) || ($dayentered > 29))) {$hasbadchars .= "Day entered is greater than 29 or is 00\t";}
565  
566 return (join "\t", $yearentered, $monthentered, $dayentered, $hasbadchars)
567  
568 } #parse008date
569  
570  
571  
572 ##########################
573 ##########################
574 ##########################
575  
576 =head2 counting_print ($modcount)
577  
578 Prints a running count (when called from a loop) based on MOD_INTERVAL.
579 Argument is current count
580 use constant MOD_INTERVAL => ###put number here###;
581  
582 =cut
583  
584 ######################################
585 ###for counting_print()
586 use constant MOD_INTERVAL => "1000";
587 ####
588  
589 sub counting_print {
590 my $modcount = shift;
591 if ($modcount % MOD_INTERVAL == 0) {
592 print "passing $modcount\n";
593 } #if
594 } #counting_print
595  
596 ##########################
597 ##########################
598 ##########################
599  
600 =head2 startstop_time()
601  
602 Start stop time is called when a program starts
603 or finishes, to see how long it takes to complete.
604 Returns time in hour:min:second format,
605 with seconds<10 being single digit. (to fix later)
606  
607 =cut
608  
609 ###################################
610  
611 sub startstop_time {
612  
613 my $dayornight;
614 my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
615 $year+=1900;
616 if ($hour >12) {$hour-=12; $dayornight="p.m.";}
617 elsif ($hour == 12) {$dayornight="p.m.";}
618 else {$dayornight="a.m.";}
619 if ($min < 10) {$min = "0".$min;}
620 if ($sec < 10) {$sec = "0".$sec;}
621 return "$hour:$min:$sec $dayornight\n"
622 }
623  
624 ##########################
625 ##########################
626 ##########################
627  
628 =head2 updated_record_hash()
629  
630 Note: Creates an hash of control numbers (001) and associated raw MARC data from input file.
631 Use with compare records script. Call to initialize updated record array variable prior to entering loop.
632 Prompts for updated record file if the name (or path) of one is not passed in.
633 Prints running count of records based on counting_print function. Works only with USMARC input files.
634  
635 =head1 NOTE WARNING (on updated_record_hash)
636  
637 This may be very memory intensive as it stores raw MARC for each record in the updated (first) file, with its associated control number.
638 40000+ records (43815K on disk) take approximately 102,192K+ to read in and then dereference.
639 YOU HAVE BEEN WARNED!!!
640  
641 =head2 TO DO (on updated_record_hash)
642  
643 Reduce memory usage, probably by learning how to tie hash to file instead of storing everything in memory.
644  
645 =cut
646  
647 sub updated_record_hash {
648  
649 use MARC::Batch;
650 my %updatedrechash;
651  
652 #retrieve file name if one was passed
653 my $inputfile = shift;
654 #otherwise get file name
655 unless ($inputfile) {
656 print ("What is the updated record file?:");
657 $inputfile = <>;
658 chomp $inputfile;
659 #remove double quotes inserted when drag-dropping from Windows
660 $inputfile =~ s/^\"(.*)\"$/$1/;
661 }
662  
663 #initialize $batch as new MARC::Batch object
664 my $batch = MARC::Batch->new('USMARC', "$inputfile");
665 my $recordno = 0;
666  
667 while (my $record = $batch->next()) {
668  
669 #get control number for the record
670 my $controlnumb = $record->field('001')->as_string();
671  
672 #use $controlnumb as hash key to full raw MARC string
673 $updatedrechash{$controlnumb} = $record->as_usmarc();
674 $recordno++;
675 MARC::BBMARC::counting_print ($recordno);
676  
677 } #while
678  
679 ###testing ###
680 print "$recordno records read\n";
681 ###/testing ###
682  
683 return \%updatedrechash;
684  
685 } #updated_record_hash
686  
687 ##########################
688 ##########################
689 ##########################
690  
691 =head2 as_array
692  
693 Add-on method to MARC::Field. Breaks MARC::Field into a flat array of subfield code and subfield data pairs.
694 Based on example 9 of the MARC::Doc::Tutorial.
695  
696 head2 Example (as_array)
697  
698 my $field043 = MARC::Field->new('043', '', '', 'a' => 'n-us---', 'a' => 'e-uk---', 'a' => 'a-th---' );
699  
700 my $field043_arrayref = $field043->as_array();
701 my @field043_array = @$field043arrayref;
702  
703 # @field043_array is: ('a', 'n-us---', 'a', 'e-uk---', 'a', 'a-th---')
704  
705 =head2 TO DO (as_array)
706  
707 Add ability to optionally pass in regex to find in subfields, returning positions of the matches (in a second array ref).
708  
709 =cut
710  
711 sub as_array {
712  
713 use MARC::Field;
714 my $self = shift;
715  
716 my @field_as_array = ();
717 my @subfields = $self->subfields();
718  
719 # break subfields into code-data array (so the entire field is in one array)
720 while (my $subfield = pop(@subfields)) {
721 my ($code, $data) = @$subfield;
722 unshift (@field_as_array, $code, $data);
723 } # while
724  
725 return (\@field_as_array)
726  
727 } # as_array
728  
729 ##########################
730 ##########################
731 ##########################
732  
733 ##########################
734 ##########################
735 ##########################
736  
737 ##########################
738 ##########################
739 ##########################
740 ###End main subroutines###
741 ##########################
742 ##########################
743 ##########################
744  
745  
746 ##########################
747 ##########################
748 ##########################
749  
750  
751 =head2
752
753 ########################
754 ### Program template ###
755 ########################
756 ###########################
757 ### Initialize includes ###
758 ### and basic needs ###
759 ###########################
760
761 ##Time coding to wrap around program to determine how long execution takes:
762
763 ##########################
764 ## Time coding routines ##
765 ## Print start time and ##
766 ## set start variable ##
767 ##########################
768
769 use Time::HiRes qw( tv_interval );
770 # measure elapsed time
771 # (could also do by subtracting 2 gettimeofday return values)
772 my $t0 = [Time::HiRes::time()];
773 my $startingtime = MARC::BBMARC::startstop_time();
774 # do bunch of stuff here
775 #########################
776 ### Start main program ##
777 #########################
778 ############################################
779 # Set start time for main calculation loop #
780 ############################################
781 my $t1 = [Time::HiRes::time()];
782 my $runningrecordcount=0;
783 #####################################
784 ## Place the following within loop ##
785 #####################################
786 $runningrecordcount++;
787 MARC::BBMARC::counting_print ($runningrecordcount);
788 ##########################
789 ### Main program done. ##
790 ### Report elapsed time.##
791 ##########################
792
793 my $elapsed = tv_interval ($t0);
794 my $calcelapsed = tv_interval ($t1);
795 print sprintf ("%.4f %s\n", "$elapsed", "seconds from execution\n");
796 print sprintf ("%.4f %s\n", "$calcelapsed", "seconds to calculate\n");
797 my $endingtime = MARC::BBMARC::startstop_time();
798 print "Started at $startingtime\nEnded at $endingtime";
799
800 print "\n\nPress Enter to quit";
801 <>;
802 #####################
803 ### END OF PROGRAM ##
804 #####################
805
806 =cut
807  
808 1;
809  
810 =head1 SEE ALSO
811  
812 MARC::Record -- Required for this module to work.
813  
814 MARC::Lintadditions -- Extension of MARC::Lint (in the MARC::Record distribution) for checks involving individual tag checking.
815  
816 MARC::Errorchecks -- Extension of MARC::Lint (in the MARC::Record distribution) for checks involving cross-field checking.
817  
818 MARC pages at the Library of Congress (http://www.loc.gov/marc)
819  
820 =head1 CHANGES/HISTORY
821  
822 Version 1.08: Updated Oct 31, 2004. Released Dec. 5, 2004.
823  
824 -New method, as_array, an add-on to MARC::Field which breaks down a MARC::Field object into a flat array, returns a ref to that array.
825 -Misc. cleanup.
826  
827 Version 1.07: Updated Aug. 30-Oct. 16, 2004. Released Oct. 17, 2004.
828  
829 -Moved subroutine getcontrolstocknos() to MARC::QBIerrorchecks
830 -Moved validate007() to Lintadditions.pm
831 -Moved validate008() and related subs to Errorchecks.pm
832 --(Left readcodedata() in BBMARC, but it is now duplicated in Errorchecks.pm, along with a modified version in Lintadditions.pm).
833 --Also left parse008date, which may have uses outside of error checking.
834 -Updated read_controlnos([$filename]) with minor changes.
835 --This subroutine could be rewritten in a more general way, since it simply reads all lines from a file into an array and returns that array.
836
837 Version 1.06: Updated Aug. 10-22, 2004. Released Aug. 22, 2004.
838  
839 -Implemented VERSION (uncommented)
840 -Added subroutine getcontrolstocknos()
841 -General readability cleanup (added tabs)
842 -Bug fix in C<validate008> for date2 check
843
844 Version 1.05: Updated July 3-17, 2004. Released July 18, 2004
845  
846 -Cleaned some documentation
847 -Added global variable in hopes of improving efficiency of language/GAC/country code validation
848 -Modified C<validate008> and/or C<readcodedata()> to use the new global variable.
849 -Moved C<readcodedata()> and C<parse008date> above C<validate008>
850  
851 Version 1.04: Updated June 16, 2004, released June 20, 2004
852  
853 -Updated as_formatted2() to work with MARC::Record 1.38 (is_control_field() instead of is_control_tag()
854 -Fixed bug in validate008 for visual materials running time (hypen was not escaped, so it was being interpreted as a range indicator).
855 -Added parse008date($) to allow user to enter yymmdd and get yyyy\tmm\tdd\t$error string back (for other uses).
856 -Added DATA containing codes from the MARC lists for Countries, Geographic Areas, and Languages, to 2003. Each code set is separated by tabs, and Obsolete codes are given following each set of valid codes, in the same format.
857 -Added readcodedata() subroutine for reading in the data and returning the data in an array for use by validation code, such as in validate008()
858 -Modified validate008 subroutine to use the DATA to validate language and country codes.
859  
860 Version 1.03: Updated June 10, not released.
861  
862 -Contained many of the changes in 1.04, but 1.04 contains the update to validate008, so I wanted a new version.
863  
864 Version 1.02: Updated May 27, 2004, released May 31, 2004
865  
866 -added updated_record_hash() (not yet tested, highly memory intensive)
867 -cleaned some documentation
868  
869 Version 1.01: Updated Apr. 28, 2004, released May 1, 2004
870  
871 -Added validate008()
872 -Changed as_formatted2() in attempt to remove extra spaces between subfields
873 -Changed getthreedigits() to allow wildcards (.)
874  
875 Version 1 (original version, lacked version designation): First release, Jan. 5, 2004
876  
877 =head1 LICENSE
878  
879 This code may be distributed under the same terms as Perl itself.
880  
881 Please note that this module is not a product of or supported by the
882 employers of the various contributors to the code.
883  
884 =head1 AUTHOR
885  
886 Bryan Baldus
887 eijabb@cpan.org
888  
889 Copyright (c) 2003-2004
890  
891 ##methodchecking code:
892 ### put this in scripts if adding it to BBMARC fails:
893 # else {
894 # *MARC::File::skipget = *MARC::BBMARC::skipget;
895 # };
896  
897 ###########################################
898 ### For Windows/DOS, end programs with: ###
899 #print "Press Enter to continue"; #########
900 #<>; ######################################
901 ############################################
902  
903  
904 =cut
905  
906  
907 1;
908  
909 __DATA__