in reply to Re: headache with arrays.
in thread headache with arrays.
If you actually needed the matches, it's simple enough to adapt the above to stick them on an array:my( $x_lo, $x_hi ) = ( -180, -170 ); my( $y_lo, $y_hi ) = ( -130, -120 ); my $count = 0; while (<>) { my( $x, $y ) = split; if ( $x >= $x_lo && $x <= $x_hi && $y >= $y_lo && $y <= $y_hi ) { $count++; } } print "$count matches.\n";
And here's a golfish version:my( $x_lo, $x_hi ) = ( -180, -170 ); my( $y_lo, $y_hi ) = ( -130, -120 ); my @matches; while (<>) { my( $x, $y ) = split; push @matches, [ $x, $y ] if $x >= $x_lo # slighly different syntax, && $x <= $x_hi # just to mix things up. :-) && $y >= $y_lo && $y <= $y_hi; } print scalar(@matches), " matches.\n";
my( $x_lo, $x_hi ) = ( -180, -170 ); my( $y_lo, $y_hi ) = ( -130, -120 ); my @matches = grep { $_->[0] >= $x_lo && $_->[0] <= $x_hi && $_->[1] >= $y_lo && $_->[1] <= $y_hi } map [ split ], <>;
|
|---|