CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
array subtraction

 



dis
New User

Mar 2, 2011, 3:23 AM

Post #1 of 2 (539 views)
array subtraction Can't Post

 Dear all,
i have a file with numbers such as -
0.116 1.182 1.649 1.516
22.782 25.953 27.072 39.960
25.953 27.072 39.960 1.516
seperated by blank lines . I need to subtract the second array from the first , third array from second and so on till the end of the file
such that i get "difference" of the first value ( 0.116-22.782 ) , second value (1.182-25.953) etc

I use the while loop but the second list is not read in (something wrong here ! Frown ) . i.e list 2 should be assigned from the second array till the end


Code
use List::MoreUtils qw<pairwise>; 

while (<IN>){
my @list1 = split(' ',<IN>,1);
my @list2 = split(' ',<IN>);
my @difference = pairwise { $b- $a } @list2, @list1; # first element of list1,list 2 and so on
print OUT "@difference\n";
}

I am a bit confused here .
Please give me some suggestions,
thanks
dis


BillKSmith
Veteran

Mar 2, 2011, 10:22 AM

Post #2 of 2 (528 views)
Re: [dis] array subtraction [In reply to] Can't Post

Please do not doulbe post.
Good Luck,
Bill

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives