I'm having an interesting dilemma with Error.pm and END blocks that I was hoping I could get some insight into. I appreciate any help anyone can give.

The problem is as follows:

#!/usr/bin/perl -w use strict; use Error qw( :try ); my $var = "Hello"; END { print $var, "\n"; try { print $var, "\n"; } catch Error with { print "Whoa, got an error!\n"; }; }


Gives me:
Hello
Hello

while this:
#!/usr/bin/perl -w use strict; use Error qw( :try ); my $var = "Hello"; END { try { print $var, "\n"; } catch Error with { print "Whoa, got an error!\n"; }; }


gives me
Use of uninitialized value in print at testend2.pl line 11.

I could see the second one not working, but why does printing (or just using or even just saying $var;) make it work inside the try block??

Is this a problem with Error.pm or a standard issue occurrence?

--------------
It's sad that a family can be torn apart by such a such a simple thing as a pack of wild dogs

In reply to Variables out of scope using END and Error.pm by RazorbladeBidet

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.