I know this isn't part of your question, but I also want to add that you should read perldoc perlvar, specifically the part on special variables $a and $b. Long story short, don't use variables with those names, they're reserved. Besides, they're horrible names. $x and $y are less horrible only because they have standard mathematical meanings.

Thus, your code should be more like this:

use strict; use warnings; # important, too. #-- variables and handles my @Matrix = map { [ (0) x 361 ] } 0..360; #--Open the input and output files # use 3-arg open, use lexical filehandle, don't interpolate a variable # that doesn't need anything added to it, i.e., "$inf" is bad, but "$i +nf-foo" # is not, report WHY open fails, not merely that it has failed. open my $in, '<', $foo or die "Can't read $inf: $!"; # lexical $line with minimal scope, check for definedness # (if you have a line that is "0\n", you'll find your original code # will terminate early). while (defined (my $line = <IN>)) { # usually, split ' ', $line is what you want instead of /\s+/. # but they do slightly different things, so I'm not changing it. # Added "my" so we create a new @result each time. my @result = split(/\s+/, $line); # I'm guessing here since I don't know where $phi and $psi really # come from. my $phi = int($result[0]); my $psi = int($result[1]); # use $ instead of @ to signify we want a scalar value from # the array. Use ++ instead of += 1 because it's more idiomatic # though technically it's no big deal either way. $Matrix[$phi+180][$psi+180] ++; }
Note that you're going from angle 0 through 360, which means that you're duplicating the ends. Normally, I'd think you'd want just 0..359 - because 360 and 0 are the same angle.


In reply to Re: perl error by Tanktalus
in thread perl error by topaz

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.