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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.