push(@pages, $_); #semi colon added
Perl doesn't care if there's a semicolon there. Generally it's OK not to have one at the end of a block.
But I'd say that the error messages from Perl are a bit cryptic from time to time; for a newbie, it can be somewhat hard to figure out what went wrong.
What you can do is to forget, first, that this is a CGI. Comment out the "use CGI::Carp" and put in instead
and then run Perl in check-mode: perl -cw myScript.pl
and look at the output. You'll get a moderately less cryptic output that starts:
Scalar value @filenames[$i] better written as $filenames[$i] at xx.pl
+line 71 (#1)
(W syntax) You've used an array slice (indicated by @) to select a
single element of an array. Generally it's better to ask for a sc
value (indicated by $). The difference is that $foo[&bar] always
behaves like a scalar, both when assigning to it and when evaluati
argument, while @foo[&bar] behaves like a list when you assign to
and provides a list context to its subscript, which can do weird t
if you're expecting only one subscript.
On the other hand, if you were actually hoping to treat the array
element as a list, you need to look into how references work, beca
Perl will not magically convert between scalars and lists for you.
Possible unintended interpolation of @filenames in string at xx.pl lin
Scalar found where operator expected at xx.pl line 72, near "] $title"
(S) The Perl lexer knows whether to expect a term or an operator.
+ If it
sees what it knows to be a term when it was expecting to see an
operator, it gives you this warning. Usually it indicates that an
operator or delimiter was omitted, such as a semicolon.
Global symbol "@pages" requires explicit package name at xx.pl line 11
Global symbol "@filenames" requires explicit package name at xx.pl lin
Global symbol "@titles" requires explicit package name at xx.pl line 1
This should start you on your way to fixing the problem. The "Global symbol...requires explicit package name" can be cured by declaring your variables using my.
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:
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.
| & || & |
| < || < |
| > || > |
| [ || [ |
| ] || ] ||