




|
Tech Tips19
How to compare two arrays in Perl?
Author: Ben|Date: 2009/05/16|Back to Tech Tips
Two arrays has two fields, A1 B1 and A2 B2, respectively, where A is coordination and B is A’s value. Please calculate the proportion of B1 and B2 if A1 and A2 is the same or similar:
#!/usr/bin/perl -w my @data = qw( 1 3 ); my @data1 = qw( 2 10 ); $coor_diff_allow = 1; if ( abs( $data[ 0 ] - $data1[ 0 ] ) <= $coor_diff_allow ) { print "\nThe ratio of values is : ", $data[1]/$data1[1] ,"\n"; exit 1; } else { print "The coordination is not even close.\n"; exit 1; } |