Urbs has asked for the wisdom of the Perl Monks concerning the following question:
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!!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Adding numeric values while keeping string values
by ikegami (Patriarch) on Aug 17, 2009 at 16:03 UTC | |
|
Re: Adding numeric values while keeping string values
by JavaFan (Canon) on Aug 17, 2009 at 16:43 UTC | |
|
Re: Adding numeric values while keeping string values
by ack (Deacon) on Aug 17, 2009 at 17:59 UTC | |
by ack (Deacon) on Aug 17, 2009 at 18:12 UTC | |
by alexm (Chaplain) on Aug 17, 2009 at 19:23 UTC | |
|
Re: Adding numeric values while keeping string values
by dwm042 (Priest) on Aug 17, 2009 at 18:53 UTC |