## perl sum 2nd field in an array

perl sum 2nd field in an array
# 1
09-09-2010
perl sum 2nd field in an array

Hi Everyone,

assume @record=(1,2,3), so the result is 6.
if @record=("1 3","2 3","3 3"), would like to sum up the 2nd field of this array, the result is 9.

Thanks

---------- Post updated at 03:45 AM ---------- Previous update was at 03:38 AM ----------

err, i think i still use back the for loop to complete this task.
 jimmy_y View Public Profile for jimmy_y Find all posts by jimmy_y
# 2
09-09-2010
Split the second field, and then sum it up.
 thegeek View Public Profile for thegeek Find all posts by thegeek

Test Your Knowledge in Computers #460
Difficulty: Medium
The 64-bit timestamps used by NTP consist of a 32-bit part for seconds and a 32-bit part for fractional second.
True or False?

## Help reading the array and sum of the array elements

Hi All, need help with reading the array and sum of the array elements. given an array of integers of size N . You need to print the sum of the elements in the array, keeping in mind that some of those integers may be quite large. Input Format The first line of the input consists of an...

## Combine Similar Output from the 2nd field w.r.t 1st Field

Hi, For example: I have: HostA,XYZ HostB,XYZ HostC,ABC I would like the output to be: HostA,HostB: XYZ HostC:ABC How can I achieve this? So far what I though of is:

## Float array sum

Hi everyone, I'm having some trouble with float array. When i try to get the array sum with float numbers i get this error line 39: soma + 2.34 | bc: syntax error: invalid arithmetic operator (error token is ".34 | bc") 26 Somar() { 27 echo "Quantos numeros deseja somar?" 28 read...

## Calculate sum of the field

Hi All, I need to calculat the sum of the particular field in text file. And the datatype of the field in file is decimal(18,2). If the file is small, then I am facing any problem. But the file is huge, then the result is converted into exponential format. I tried using various command thr...

## Perl - use search keywords from array and search a file and print 3rd field when matched

Hi , I have been trying to write a perl script to do this job. But i am not able to achieve the desired result. Below is my code. my \$current_value=12345; my @users=("bob","ben","tom","harry"); open DBLIST,"<","/var/tmp/DBinfo"; my @input = <DBLIST>; foreach (@users) { my...

## perl, put one array into many array when field is equal to sth

Hi Everyone, #!/usr/bin/perl use strict; use warnings; my @test=("a;b;qqq;c;d","a;b;ggg;c;d","a;b;qqq;c;d"); would like to split the @test array into two array: @test1=(("a;b;qqq;c;d","a;b;qqq;c;d"); and @test2=("a;b;ggg;c;d"); means search for 3rd filed. Thanks find the...

## perl sort array by field

Hi Everyone, Any simple code can simplify the code below, please advice. Thanks # cat 2.pl #!/usr/bin/perl use warnings; use strict; my @aaaaa = <DATA>; my @uids; foreach (@aaaaa) { my @ccccc = split (",", \$_); push @uids, \$ccccc;...

## Perl script to find particular field and sum it

Hi, I have a file with format a b c d e 1 1 2 2 2 1 2 2 2 3 1 1 1 1 2 1 1 1 1 4 1 1 1 1 6 in column e i want to find all similar fields ( with perl script )and sum it how many are there for instance in format above. 2 - 2 times 4 - 1 time 6 - 1 time what i use is ...

## Sort alpha on 1st field, numerical on 2nd field (sci notation)

I want to sort alphabetically on the first field and sort in descending numerical order on the 2nd field. With a normal "sort -r -n" it does this: abc ||| 5e-05 ||| bla abc ||| 3 ||| ble def ||| 1 ||| abc def ||| 0.2 ||| def As you can see it ignores the fact that 5e-05 is actually 0.00005...

## Perl - if conditions is meet, push the last field of \$_ into an array

I am using a seed file shown below to separate cisco devices by ios/os type. I want to bunch all the devices based on ios/os version. Once I find a match, I only want to push the ip address into the appropriate array. Example of seedfile 8 host1 (C3500XL-C3H2S-M) 11.0(5)WC17 10.1.44.21 9...