Not sure what you mean by:
I have a hashref, @records...
I thought (more knowlegeable monks will no doubt correct me if I'm wrong) that hashrefs were scalars, not arrays.
Anyway, if perchance you mean that you have this data in a file somewhere, you could do something like this (note that, to simplify, I use __DATA__ instead of opening the file and reading from the filehandle):
use strict; use warnings; my $headline = <DATA>; my %HoA; while ( <DATA> ) { s/null/0/g; # no warnings 'numeric'; next unless /^\w/; chomp; my ( $name, @res ) = split /\s*\|\s*/; $HoA{$name} = ! $HoA{$name} ? [ @res ] : [ map { $HoA{$name}[$_] + $res[$_] } 0 .. $#res ]; } print $headline; { local $" = ' | '; print "$_: @{ $HoA{$_} }\n" for ( keys %HoA ); } __DATA__ name | passed | failed | pending -----+--------+--------+--------- xxx | null | 2 | null xxx | 30 | null | null xxx | null | null | 10 yyy| 6 | null | null
The first line in the while() loop changes all your instances of 'null' to '0'. If you really don't want to do this, the easiest solution is probably to remove that line and uncomment the following line. There are other solutions, but I haven't really the time to find any that don't complicate the code significantly (hey, anyone else out there?...)
hth
dave
In reply to Re: cleaning up multiple lines...
by Not_a_Number
in thread cleaning up multiple lines...
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |