i can recommend using
perlsub, "Private Variables via my()".
just quoting from there:
The "my" operator declares the listed variables to be lex-
ically confined to the enclosing block, conditional
("if/unless/elsif/else"), loop ("for/fore-
ach/while/until/continue"), subroutine, "eval", or
"do/require/use"'d file.
you're doing something like
# scope file
if ($condition1) {
# scope if
my $inner = 1;
}
else {
# scope else
my $inner = 2;
}
# scope file
print $inner;
but $inner is only seen in "scope if" and "scope else".
no variable $inner has ever been defined in "scope file".
so just add a
my $inner; before your if/else-stataments.
additionally your logic doesn't make sense to me. you say,
if condition1, set the variables to something, if
condition2, set them to something else, and otherwise
don't set them, but print them. but if they aren't
set the print seems pretty useless and will issue a warning.
there are also fine tutorials here in the tutorials section about my(), strict etc. where you might find answers.
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.