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; } }

In reply to problem with global variables going out of scope by Kelly Grant

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.