/^Request Number:/
/^Status:/
/^Affected User:/
...
/\d+\s+minutes\s+\d+\s+seconds/ # (update: had forgotten 3rd "\s+")
####
my %record;
if ( /^Request Number:/ ) {
my @flds = ();
push @flds, substring( $_, 0, 40 );
push @flds, substring( $_, 40, 26 );
push @flds, substring( $_, 66 ); # rest of line
for my $fldname ('Request Number', 'Parent', 'Priority') {
(my $val = shift @flds) =~ s/^$fldname\s*:\s*//;
$val =~ s/\s*$//; # update: remove leading/trailing whitespace...
$record{$fldname} = $val; # which means this could be "" -- not a problem
}
}
# and likewise for each other type of line
####
$/ = "end-of-record-string"; # whatever that may be
while (<>) { # this now reads one whole record into $_
my @lines = split( /\n/ );
my %record
while ( @lines ) {
$_ = shift @lines;
# proceed with parsing record fields as above...
if ( /^Request Number:/ ) {
...
}
elsif ...
}
store_to_database( \%record );
}