develooper Front page | perl.perl5.porters | Postings from April 2010

[perl #5249] Symbol table aliasing not DWIM'ing except under Debugger

Thread Previous | Thread Next
From:
Eric Brine via RT
Date:
April 30, 2010 01:42
Subject:
[perl #5249] Symbol table aliasing not DWIM'ing except under Debugger
Message ID:
rt-3.6.HEAD-27388-1272564734-1308.5249-15-0@perl.org
I suspect that fixing this problem will incur a performance penalty.

There are three workarounds:

1) Perform the aliasing sooner (e.g. at compile-time).

2) Use symbolic references instead to access the variables (forcing
run-time name resolution).

3) Delay the compilation of the variable access (e.g. by using eval).


----- BEGIN  CODE -----
$foo::bar::poit::var = "fbp";
$g::var              = "g";
BEGIN {
$h::var              = "h";
}

*g:: = \%foo::bar::poit::;  # Alias g:: to some long thing.
BEGIN {
*h:: = \%foo::bar::poit::;  # Alias h:: to some long thing.
}

# 1) Do aliasing sooner
print "$foo::bar::poit::var\n";      # Prints fbp
print "$g::var\n";                   # Prints g
print "$h::var\n";                   # Prints fbp

# 2) Lookup variable later.
{ no strict 'refs';
print "${'foo::bar::poit::var'}\n";  # Prints fbp
print "${'g::var'}\n";               # Prints fbp
print "${'h::var'}\n";               # Prints fbp
}

# 3) Compile variable access later
eval '
print "$foo::bar::poit::var\n";      # Prints fbp
print "$g::var\n";                   # Prints fbp
print "$h::var\n";                   # Prints fbp
';
----- END CODE -----


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About