Thread Seltsames Problem mit mod_perl und RegEx (12 answers)
Opened by windtaenze at 2007-08-06 19:39

ptk
 2007-08-08 00:59
#97747 #97747
User since
2003-11-28
3645 Artikel
ModeratorIn
[default_avatar]
Ich vermute, dass ModPerl::Registry ähnlich wie Apache::Registry arbeitet. Intern funktioniert es so, dass aus dem Skript ein großes sub wird. Das sieht dann ungefähr so aus:
Code: (dl )
1
2
3
4
5
6
7
8
use warnings;

sub script {
my $globale_variable;
sub function {
$globale_variable;
}
}
Wenn man dieses Skript aufrufst, bekommt man die Warnung:
Code: (dl )
Variable "$globale_variable" will not stay shared at ...
perldiag meint hierzu:
Quote
When the inner subroutine is called, it will probably see the value of
the outer subroutine's variable as it was before and during the *first*
call to the outer subroutine; in this case, after the first call to the
outer subroutine is complete, the inner and outer subroutines will no
longer share a common value for the variable. In other words, the
variable will no longer be shared.

Das kann man leicht nachprüfen, indem man script() zweimal aufruft und die Referenz von $globale_variable jeweils in script() und in function() ausgeben lässt.

Meine Lösung hier bei solchen Fällen ist es, auf "my" außerhalb von subs (das meine ich mit "global") zu verzichten und "our" oder "use vars" zu verwenden. Oder man verzichtet ganz auf Apache::Registry/ModPerl::Registry und schreibt nur rohe PerlHandler (wie es der Autor von Apache::Registry mittlerweile auch macht).

View full thread Seltsames Problem mit mod_perl und RegEx