I am going to by the llama later today. In the meantime, I need some basic help with my hash. I had a line that was originally:

server,1212,123123,12341234

I could have several lines for each server and I needed to add the values while maintaining the CSV format. I have added some string data to the end of the lines that I would like to maintain as well. The code below however, complains that the data is not numeric and seems to drop the non-numeric data. How can I modify it to add the numeric data together while maintaining the non-numeric data?

while (<CSV_OUT>) { chomp; my @line = split /,/; my $name = shift @line; if (exists $servers{$name}) { foreach my $index (0..$#line) { $servers{$name}[$index] += $line[$index]; } } else { $servers{$name} = [@line]; } }

example data source:

cihcrppmon02,standard_unix_corp-cis_shared,1703995999752,133635610485, +31055995112,12.75,54.8, ghnbu, gh_nbu02 ovpip02,standard_unix_corp-cis_shared,41851038572,14933570508,38353867 +32,2.80,10.91,ghnbu, gh_nbu02 cihcispapp247,standard_unix_corp-cis_shared,190635017908,24806407611,9 +442867181,7.68,20.19,ghnbu, gh_nbu02 wavmd003,standard_unix_corp-cis_shared,2760141244,594115253,299382152, +4.65,9.22,ghnbu, gh_nbu02

Thanks for all of your help!!


In reply to Adding numeric values while keeping string values by Urbs

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.