Well, it doesn't do all the magic for you, but quite a bit:
#!/usr/bin/perl
use warnings;
use strict;
my (@nodename, @filename, @pathname, @backupdate);
use Data::Dumper;
{
# discard heading line
my $tmp = <DATA>;
}
while (my $line = <DATA>){
chomp $line;
my ($nn, $fn, $pn, $bd) = unpack('A8xA9xA8xA15', $line);
if ($nn =~ m/\S/){
push @nodename, $nn;
push @filename, $fn;
push @pathname, $pn;
push @backupdate, $bd;
} else {
$nodename[-1] .= $nn;
$filename[-1] .= $fn;
$pathname[-1] .= $pn;
$backupdate[-1] .= $bd;
}
}
print Dumper([\@nodename, \@filename, \@pathname, \@backupdate]);
#1234567890123456789012345678901234567890123
__DATA__
NodeName FileName PathName BackupDate
BD3101 bananaswi \breakfa 2007-03-06
ithapple st\fruit 14:02:31.000000
s.gif s\tree\
TP4223 chocolate \sweet\d 2006-02-28
caramelfu esserts\ 21:16:41.000000
dge.gif hersheys\
EO2123 tofuwith \organic\ 2007-07-16
peas.gif vegetable 13:55:06.000000
s\legumes\
Actually the data would better be stored in a two dimensional array.
Note that all lines that don't have the Backup Date field need to be padded with whitespaces at the end of the line to be long enough, if that's not the case you'd have to pad them manually before using unpack.
|