I'm not entirely sure what the best way to explain this is, but here goes. I'm trying to create a graph. i have a text file that looks something like this
-70.6 -27.5 -60.8 52.9 -123.0 -132.9 110.1 119.9 -62.4 -45.6
I am currently trying to write a perl script to do the following

Convert the numbers so instead of being between -180 and 180 they are between 0 and 360.
Place the resulting x, y values into blocks of 5. So, now if we have a value of 12.3 it's now placed in the '10-15' block (I hope that makes sense).
Create a two dimensional array, and using the blocked x y values, increment the corresponding element of the array by one
This is what I have managed so far.

#!/usr/bin/perl use strict; use warnings; my $input = $ARGV[0]; my $x = 0; my $y = 0; my $zeroed_x = 0; my $zeroed_y = 0; my $binned_x = 0; my $binned_y = 0; my @binarray = (); open(INPUT, "$input") || die "Oops! Can't open INPUT file: $!\n"; while(<INPUT>) { $x = substr($_, 0, 6); $y = substr($_, 7, 6); $zeroed_x = ConvertToFromZero($x); $zeroed_y = ConvertToFromZero($y); $binned_x = BinAngles($zeroed_x); $binned_y = BinAngles($zeroed_y); $binarray[$binned_x][$binned_y]++; } for(my $i = 0; $i < @binarray; $i++) { for(my $j = 0; $j < @binarray; $j++) { print "$binarray[$i][$j]\n"; } } ###################################################### sub ConvertToFromZero { my ($axis) = @_; my $zeroed_axis = 0; $zeroed_axis = 180 + $axis; return($zeroed_axis); } ####################################################### sub BinAngles { my ($axisforbin) = @_; my $binnedaxis = 0; $binnedaxis = int($axisforbin/5); return($binnedaxis); }
I get the following error which I don't understand (google doesn't help)
Use of uninitialized value in concatenation (.) or string at ./script. +pl line 34, <INPUT> line 22.
Any suggestions much appreciated.

In reply to Problems processing data for graph by Angharad

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.