I'm a relative newbie to Perl, and I've been searching around the Monastery, the Llama book and the Camel book, and I'm not getting why my variables are going out of scope. I parse command line values and set a scalar variable defined in my Main (though Main is not named, just using the defaults). I then call a subroutine to open files, and other routines to process the files. I'm using 'our' in the sub where I reference the variable, but it is still out of scope sometimes.
I appreciate any help anyone can provide
Kelly
Here is a snippet from the file:
use strict;
use warnings;
use bytes;
#...
my $showPUV = 0;
my $showPUVdesc = "";
# Call a sub, which calls a sub, etc...
# The Main doesn't end until all files have been processed
sub FilterMessage {
$Line = $_[0];
our $showPUV;
our $PUV;
our $Report;
our $EVENTNAME;
our $EVENTTEXT;
Clear_Arguments();
Parse_Messages();
## IF we care about the PUV and it is NOT our PUV, don't show it
# if (( defined $main::showPUV ) and ( defined $main::PUV )) {
if ( $showPUV != 0 ) { ## This is undefined sometimes!!
if ( $showPUV != $PUV ) { return $FALSE; }
}
# }
## else this test is OK, the line can be shown at this point
if ( $Report eq "events" ) {
if (( bytes::length $EVENTNAME > 0 ) or
( bytes::length $EVENTTEXT > 0 )) {
return $TRUE;
}
}
elsif ( $Report eq "comms" ) {
## need to do some more work here
return $TRUE;
}
else {
return $TRUE;
}
}
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.