in reply to headache with arrays.

I've written some code that (I think) does what you want. Being new to Perl, it will probably take you some study before you understand the nested structures (array of arrays, which are done with references). I recommend perldoc perlreftut.
# This is an "array of arrays". Each row is one set of ranges, # a pair of Xs and a pair of Ys my @ranges = ([-180, -170, -130, -120], [-180, -170, -110, -105]); # This array is going to store the counts for each row of @ranges # It is initialized to zero for each row my @range_counts = (0) x @ranges; # This reads default input: file(s) on command-line or STDIN while (<>) { # split the line on whitespace my ($x, $y) = split; # Count through the rows in @ranges for my $R (0..$#ranges) { # Compare if ($x >= $ranges[$R][0] and $x < $ranges[$R][1] and $y >= $ranges[$R][2] and $y < $ranges[$R][3]) { # Increment counter ++$range_counts[$R]; } } } # Go through the rows in @ranges again, printing them and the # corresponding count for my $R (0..$#ranges) { printf "(%d..%d, %d..%d): %d\n", @{$ranges[$R]}, $range_counts[$R]; }

Caution: Contents may have been coded under pressure.

Replies are listed 'Best First'.
Re^2: headache with arrays.
by Anonymous Monk on Sep 20, 2004 at 16:32 UTC
    Thank you very much. I shall give it a go and tell you how I got on :)