Using
strict and
warnings would certainly make your life (as a programmer) a little bit easier:
use strict;
use warnings;
while(<DATA>)
{
chomp;
my @pages = split(/\+\+/, $_);
my @SonarData = ();
my %DOWN = ();
C:\src\perl\perlmonks\636961>perl -wc 636961.pl
"my" variable @pages masks earlier declaration in same scope at 636961
+.pl line 17.
String found where operator expected at 636961.pl line 220, near "$ p
+rint "@SonarData\n""
Update: Your script is littered with
small, but subtle errors that are easily detected using
strict and
warnings:
- A $ before print, probably just a typo.
- Redefined variables, "my" variable $total masks earlier declaration in same scope.
- Case errors: Global symbol "$endlevel" requires explicit package name.
- Wrong use of increment as pointed out by rhesa, would be reported by warnings: Useless use of array element in void context when $endlevel is corrected to $endLevel.
Once you get your script to do what you want, take a step back and consider
refactoring (perl.com article).