in reply to MultiLine Tables into Variables
With this, I throw my code into the ring:
Update: My apologies -- I missed the part about the huge datafile. This method stores everything in memory, so that could be a problem...
#!/perl/bin/perl -w use strict; use Data::Dumper; my $spec = 'A9A10A10A15'; my $hash = {}; my $nodename = ""; my $out = {}; $_ = <DATA>; # skip the header line while (<DATA>) { #stuff everything into a hash of array refs my @arr = unpack($spec, $_); @arr = map { s/^\s+//; $_ } @arr; # remove any leading spaces if ($arr[0]) { $nodename = shift(@arr); } else { shift(@arr); } push(@{$hash->{$nodename}}, \@arr); } print Dumper($hash); # contents may be viewed in $VAR1 below for my $key (keys %$hash) { my $rows = $hash->{$key}; for (my $rownum = 0; $rownum <= $#$rows; $rownum++) { my $cols = $rows->[$rownum]; for (my $col = 0; $col <= $#$cols; $col++) { # include a space between the date/time strings my $space = ($rownum == 0 && $col == 2) ? ' ' : ''; $out->{$key}->[$col] .= $cols->[$col] . $space; } } } for my $key (keys %$out) { printf "%-7s %-25s %-29s %-30s\n", $key, @{$out->{$key}}; } __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\ __OUTPUT__ $VAR1 = { 'TP4223' => [ [ 'chocolate', '\\sweet\\d', '2006-02-28' ], [ 'caramelfu', 'esserts\\', '21:16:41.000000' ], [ 'dge.gif', 'hersheys\\', '' ] ], 'BD3101' => [ [ 'bananaswi', '\\breakfa', '2007-03-06' ], ... etc ... TP4223 chocolatecaramelfudge.gif \sweet\desserts\hersheys\ 2006-0 +2-28 21:16:41.000000 BD3101 bananaswiithapples.gif \breakfast\fruits\tree\ 2007-0 +3-06 14:02:31.000000 EO2123 tofuwithpeas.gif \organic\vegetables\legumes\ 2007-0 +7-16 13:55:06.000000
|
|---|