Before addressing your comment, let me clear up one point of confusion. In perl, the term 'global variable' means the same thing as 'package variable' (declared with 'our' or 'use vars'). You did not declare any of these. By moving the declaration, you increased the scope of a lexical variable to include the entire file.
when you see a message that a variable is not declared, it can mean any of several things.
- You forgot to declare the variable.
- You misspelled the variable
- You used the variable some place you did not intend.
- You declared the variable in too narrow a scope.
Removing 'strict' will suppress the message, but not fix any of the errors. Moving the declaration to the start of the file will probably also suppress the message. It will 'fix' the scope problem, but none of the others. In exchange, you have given up this protection against errors you may make in the future.
The solution is 'smallest possible scope'. Move the declaration not to the start of the file, but to the start of the smallest block which includes every necessary use of the variable.
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.