in reply to Re: Problems processing data for graph
in thread Problems processing data for graph
I think your code is fine, though it could be made more succinct without sacrificing clarity, and it has a strong "C accent". :-). Here's how I would "perlify" it:
use strict; use warnings; my $input = shift; my $min = -180; my $range = 360; my $bin_size = 5; my $n_bins = $range/$bin_size; my @binarray = map [ ( 0 ) x $n_bins ], 1..$n_bins; open my $in, $input or die "Oops! Can't open $input: $!\n"; while ( <$in> ) { my @indices = map to_index( $_ ), split; $binarray[$indices[ 0 ]][$indices[ 1 ]]++; } close $in or die "Failed to close $input: $!\n"; for my $row ( @binarray ) { print "$_\n" for @$row; } sub to_index { return ( $_[ 0 ] - $min )/$bin_size; }
the lowliest monk
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Problems processing data for graph
by Angharad (Pilgrim) on May 04, 2005 at 15:04 UTC |