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).
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.