in reply to Problems processing data for graph

Thank you both for your suggestions. They are much appreciated. As a general question if anyone would like to answer ... I know that theres 'more than one way to do it in perl, but is the approach I used a reasonably sensible one in your opinion?
Thanks again

Replies are listed 'Best First'.
Re^2: Problems processing data for graph
by holli (Abbot) on May 04, 2005 at 13:40 UTC
    #!/usr/bin/perl use strict; use warnings; use Data::Dumper; my @binarray; while (<DATA>) { my ($x,$y)=split / +/; my $ax = [ (0) x 72 ]; my $ay = [ (0) x 72 ]; $ax->[int ($x+180) / 5] = 1; $ay->[int ($y+180) / 5] = 1; push @binarray, [$ax, $ay]; } print Dumper (\@binarray); __DATA__ -70.6 -27.5 -60.8 52.9 -123.0 -132.9 110.1 119.9 -62.4 -45.6


    holli, /regexed monk/
Re^2: Problems processing data for graph
by tlm (Prior) on May 04, 2005 at 14:56 UTC

    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

      Thanks. Yeah, well my strongest programming language is C, and I have been using it for a lot longer than I have been using perl (although i would not claim to be an expert at C even and am certainly a novice at perl!) so I guess its not surprising my code is a bit 'C' like in nature :)

      Thanks for the tips. I'll make a perl programmer yet (in about a decade or so maybe ... lol.)

Re^2: Problems processing data for graph
by BrowserUk (Patriarch) on May 04, 2005 at 13:15 UTC
    ... but is the approach I used a reasonably sensible one in your opinion?

    You have only described the manipulations you are doing to create your graph. Without some idea about what the raw data represents and what you are hoping to discover (or just show) with your graph, it is impossible to say whether your manipulations are good or not.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
    "Science is about question the status quo. Questioning authority".
    The "good enough" maybe good enough for the now, and perfection maybe unobtainable, but that should not preclude us from striving for perfection, when time, circumstance or desire allow.