Sponsored Content
Top Forums Shell Programming and Scripting perl sum 2nd field in an array Post 302452067 by jimmy_y on Thursday 9th of September 2010 04:45:26 AM
Old 09-09-2010
perl sum 2nd field in an array

Hi Everyone,

Code:
($total+=$_) for @record;

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.
i tried " ($total+=$[2]) for @record ", cannot, please advice.

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.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

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... (1 Reply)
Discussion started by: popeye
1 Replies

2. Shell Programming and Scripting

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... (1 Reply)
Discussion started by: FrancoisCN
1 Replies

3. Shell Programming and Scripting

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 ... (14 Replies)
Discussion started by: Learnerabc
14 Replies

4. Shell Programming and Scripting

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;... (3 Replies)
Discussion started by: jimmy_y
3 Replies

5. Shell Programming and Scripting

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... (0 Replies)
Discussion started by: jimmy_y
0 Replies

6. Shell Programming and Scripting

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... (11 Replies)
Discussion started by: chidori
11 Replies

7. Homework & Coursework Questions

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... (0 Replies)
Discussion started by: lathanandhini
0 Replies

8. Shell Programming and Scripting

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... (4 Replies)
Discussion started by: berveglieri
4 Replies

9. UNIX for Dummies Questions & Answers

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: (1 Reply)
Discussion started by: alvinoo
1 Replies

10. Shell Programming and Scripting

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... (1 Reply)
Discussion started by: nishantrefound
1 Replies
PX_INSERT_RECORD(3)					     Library Functions Manual					       PX_INSERT_RECORD(3)

NAME
PX_insert_record -- Inserts a new record in the Paradox file SYNOPSIS
#include <paradox.h> int PX_insert_record(pxdoc_t *pxdoc, pxval_t **dataptr) DESCRIPTION
Inserts a new record stored in the array dataptr into a Paradox file. The position of the record will be determined by the function itself, starting at the beginning of the file and searching towards the end for a free slot. A free slot can be the result of former calls of PX_delete_record(3) or not completely filled data blocks in the input file. If there is no free slot within the file, then a new record will be added at the end. Blobs will be automatically written if a blob file was set with PX_set_blob_file(3). The memory for dataptr and the field values can be freed after PX_insert_record has been called. Each single element in the array of pointers to pxval_t can be easily created with MAKE_PXVAL(pxdoc_t *pxdoc, pxval_t *val) and setting the actual value afterwards. A quite common way to build up the record is the following: dataptr = (pxval_t **) malloc(PX_get_num_fields(pxdoc)*sizeof(pxval_t *)); MAKE_PXVAL(pxdoc, dataptr[0]); dataptr[0]->type = pxfLong; dataptr[0]->value.lval = 45; dataptr[1]->type = pxfAlpha; dataptr[1]->value.str.val = "test"; dataptr[1]->value.str.len = 4; PX_insert_record(pxdoc, dataptr); free(dataptr[0]); free(dataptr[1]); free(dataptr); There is currently no need to set the type, though it is recommended. The field types pxfMemoBLOb and pxfFmtMemoBLOb are treated like strings. Fields of type pxfAutoInc are automatically incremented if its value is set to NULL. In such a case the value is taken from the header of the database. You should not have more than one field of type pxfAutoInc in your database, otherwise the automatic incrementation will not work. RETURN VALUE
Returns the record number on success or -1 on failure. The number of the first record is 0. SEE ALSO
PX_retrieve_record(3), PX_delete_record(3), PX_update_record(3) AUTHOR
This manual page was written by Uwe Steinmann uwe@steinmann.cx. PX_INSERT_RECORD(3)
All times are GMT -4. The time now is 10:22 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy