The error is from use strict - which is good. Also check you have use warnings.

This type of problem is (almost) always due to bad code which isn't a syntax error. For instance, a stray double-quote on a line above could be wrapping my $num in a string. Mismatched parentheses, brackets or braces around this code are likely candidates. A missing semicolon to terminate a statement is another possibility. There could be other reasons.

The line where the error is reported is important - you haven't shown that here.

If you can't find the problem through simple visual inspection, try commenting out a line near the error and see if you get different (more useful) messages.

I also find it good practice to keep a mental catalogue of silly mistakes I make often and check for those first. For example, I often don't release the Shift key quickly enough, resulting in a colon, rather than a semicolon, at the end of the line, e.g.

$var1 = $hash{$key}: $var2 = some_sub(@args):

Use of an editor with syntax highlighting can also sometimes help in this situation. I understand that is a personal choice and some people prefer not to use syntax highlighting.

-- Ken


In reply to Re: requires explicit package name by kcott
in thread requires explicit package name by toniax

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.