Jack Daniels (Butch) wrote:
> It's driving me bonkers and can't afford any more psychiatic bills. The data
> is a saved .txt file when viewing from a website. The vendor will not give
> us an actual file even though we payed a montly fee for use of the database.
> I have around 5000 records that need to be converted to MARC cataloging
> records. I need to either have the data from each heading on 1 line or have
> the script extract each heading and all the subsequent lines.


This appears to do what you want:


use warnings;
use strict;

# The headers in the correct order for printing
my @ordered = qw[ Title Dewey Producer Copyrighted Physical Series Synopsis
Subjects ];
my $alternation = join '|', @ordered;


my %prepend = (
    Title       => "=LDR  00000nam  2200000Ia 45e0\n=24500\$a",
    Dewey       => "=082  \\\\\$a",
    Producer    => "=040  \\\\\$aCaSRRI\n=260\\\\\$a",
    Copyrighted => "=261  \\\\\$c",
    Physical    => "=300  \\\\\$a1 videocassette ( min.):\$bsd., col. ;\$c13 
mm.",
    Series      => "=440  0\\\$a",
    Synopsis    => "=520  \\\\\$a",
    Subjects    => "=550  \\\\\$a",
    );


open MYINPUTFILE, '<', '1000chomp.txt'
    or die "Cannot open '1000chomp.txt' $!";


my ( $heading, %record );
while ( <MYINPUTFILE> ) {
    if ( /^ {6}(($alternation)\s+.*)/ ) {
        $record{ $heading = $2 } = $1;
        }
    elsif ( /(\S.*)/ ) {
        $record{ $heading } .= " $1";
        }
    elsif ( %record ) {
        print "$prepend{$_}$record{$_}\n" for @ordered;
        print "\n";
        %record = ();
        }
    }
# Print the last record.
if ( %record ) {
    print "$prepend{$_}$record{$_}\n" for @ordered;
    print "\n";
    }

__END__



John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to