in reply to perl error
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:
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.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] ++; }
|
|---|