
dis
New User
Mar 2, 2011, 3:23 AM
Post #1 of 2
(362 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 ! ) . i.e list 2 should be assigned from the second array till the end
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
|