Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Won't jump to Sub!

by merlyn (Sage)
on Apr 17, 2001 at 00:30 UTC ( [id://72931]=note: print w/replies, xml ) Need Help??


in reply to Won't jump to Sub!

Check your web log for "variable won't stay shared" error messages. I bet you've got quite a few. {grin}

-- Randal L. Schwartz, Perl hacker

Replies are listed 'Best First'.
Re (tilly) 2: Won't jump to Sub!
by tilly (Archbishop) on Apr 17, 2001 at 01:16 UTC
    Bingo. This is absolutely going to be a problem.

    For those who saw that comment go over their heads, in mod_perl it is absolutely essential that global variables be declared with vars and not with my. The latter leads to serious black magic. Try RE (3): BrainPain-Help for one attempt at an explanation.

    Here is another.

    The key to the problem is that the subroutine has a single global name. There can only be one sub with that name in that package. Ever. However there may be many different lexical variables running around with that name. (Look up closures.) So when the one global has to figure out which lexical it names...well what is the right answer?

    This is an issue in this case because Apache is just wrapping your entire script with a sub, and calling that. So that sub is called many times, leading to many copies of the lexical variable, and the brand new one being set each time isn't being seen where you want it to be.

Re: Re: Won't jump to Sub!
by sierrathedog04 (Hermit) on Apr 17, 2001 at 06:32 UTC
    Merlyn's cryptic comment inspired me to find out what the "variable won't stay shared" message means.

    A subroutine can be named or anonymous, just as an array can be named or anonymous.

    Furthermore, a subroutine can include a lexical variable declared outside the subroutine if they are within the same lexical scope. (When a subroutine includes such a lexical variable it is called a closure.)

    But here is the catch. Normally perl only needs to compile a subroutine once. But when a subroutine is a closure, it potentially might need to recompile the subroutine more than once in case the externally-defined lexical variable changes its value.

    It is a Law of Perl that if a subroutine is both named and a closure then Perl will only compile it once. Powerful magicians like Merlyn are able to use this feature to practice Deep Mojo. For the rest of us, this feature is likely to produce unexpected results.

    So what Merlyn was saying is that he suspects that the named subroutines in the code in question contain lexical variables defined outside of the named subroutines. And he is sceptical that these completions were performed with the necessary knowledge of Perl magic needed to make them work.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://72931]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2024-04-24 11:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found