Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

First, keep in mind that
try { ... } ...
is the same thing as
try sub { ... }, ...
and that's the source of many problems.

$GLOBAL_VARIABLE falls out of scope at the end of the (.pm) file, and before 5.10.0, a reference by an anon sub isn't enough to to keep it alive.

Simplified test case:

use strict; use warnings; { my $f = 'test'; my $g = 'test'; sub f { sub { print "f: $f\n" }->(); } sub g { $g if 0; sub { print "g: $g\n" }->(); } } f(); g();
>perl589\bin\perl test.pl Use of uninitialized value in concatenation (.) or string at test.pl l +ine 9. f: g: test >perl5100\bin\perl test.pl f: test g: test

Note that adding a reference to the captured variable in the named sub — even one that's optimized away — makes it available to the anonymous sub.

A similar problem exists with eval '$s'. While not fixed, a warning was added in 5.10.0.

>perl589\bin\perl -wle"{ my $s='test'; sub f { print 's: ', eval '$s' +} } f()" Use of uninitialized value in print at -e line 1. s: >perl5100\bin\perl -wle"{ my $s='test'; sub f { print 's: ', eval '$s' + } } f()" Variable "$s" is not available at (eval 1) line 2. Use of uninitialized value in print at -e line 1. s:

In reply to Re: global variable initialization inside try{} by ikegami
in thread global variable initialization inside try{} by legova

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (6)
As of 2024-04-25 18:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found