Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re^3: Variable will not stay shared in a sporadically crashing CGI

by haukex (Archbishop)
on Oct 02, 2017 at 13:38 UTC ( [id://1200522]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Variable will not stay shared in a sporadically crashing CGI
in thread Variable will not stay shared in a sporadically crashing CGI

you can just use our $cgi instead of my $cgi

Locutus: Please, avoid globals - the "best" way to do it is to pass $cgi as an argument to the subroutines.

Replies are listed 'Best First'.
Re^4: Variable will not stay shared in a sporadically crashing CGI
by LanX (Saint) on Oct 02, 2017 at 14:02 UTC
    I'd say the problem is inter-mixing lexicals my $cgi with package symbols like named subs like sub print_document

    Changing to lexicals holding anonymous sub refs my $print_document = sub {} would solve the OP'S problem too.

    Having persistent shared globals can be a desired effect. (Initialization overhead, communication channel)

    Cheers Rolf
    (addicted to the Perl Programming Language and ☆☆☆☆ :)
    Je suis Charlie!

Re^4: Variable will not stay shared in a sporadically crashing CGI
by Anonymous Monk on Oct 02, 2017 at 13:48 UTC
    This is getting a bit off-topic, but some globals are ok. Novice programmers don't always know when they're safe and when they aren't, and they're often too timid to change a global to a local when it really needs to be done. That's why we advise people not to use globals at all. But CGI is probably safe as a global, because there's no reason to have two of them in your program.
      But CGI is probably safe as a global, because there's no reason to have two of them in your program.

      I absolutely agree with the general comment about some globals being ok if the coder knows what they are doing - but we are talking about mod_perl here, better to play it safe, and lexicals are arguably safer* in this case.

      * Update: "safer" not in the sense of security, but in less chances for things to go wrong.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (5)
As of 2024-04-16 06:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found