Captainrave
Technical User
Basically I read two files into a script:
The big file has "big" values like -
100 1000
1200 1600
1700 2050 ...
The small file with values like-
5 15
120 125
I wrote a script which finds any small value located within the big values...then for any match it is supposed to output all the values. It is also meant to perform a calculation of exactly WHERE the small value lies in the big value (in the form of a percentage). But it doesn't work:
I have no idea why it doesnt work, and I need help! If it isnt obvious why it isnt working, can someone show me how I could literally JUST output the matches found. I could dfo the calculations in excel!
Hope that makes sense! HELP!!!!
The big file has "big" values like -
100 1000
1200 1600
1700 2050 ...
The small file with values like-
5 15
120 125
I wrote a script which finds any small value located within the big values...then for any match it is supposed to output all the values. It is also meant to perform a calculation of exactly WHERE the small value lies in the big value (in the form of a percentage). But it doesn't work:
Code:
use strict;
use warnings;
open(OUTPUT,"newfile.csv");
open BIG, 'big values.xls' or die "$!";
my @big = map {[split/\s+/]} <BIG>;
close BIG;
open SMA, 'small values.csv' or die "$!";
LOOP: while (<SMA>) {
my ($s,$e) = split(/\,/);
foreach my $array (@big) {
if ($s >= $array->[0] && $e <= $array->[1]) {
calculate($s,$e,$array->[0],$array->[1],$.);
next LOOP;
}
}
}
close SMA;
close OUTPUT;
sub calculate {
my ($small_start, $small_end, $big_start, $big_end, $line_num) = @_;
my $calculation = ( ( ($big_start/$big_end) / ($small_start/$small_end) ) * 100 );
print OUTPUT "small_start,$small_end,$big_start,$big_end,$calculation,/n";
}
I have no idea why it doesnt work, and I need help! If it isnt obvious why it isnt working, can someone show me how I could literally JUST output the matches found. I could dfo the calculations in excel!
Hope that makes sense! HELP!!!!