in reply to Re^2: symbol table vs. eval
in thread symbol table vs. eval
You need to use our $my_variable_name; You may thing hardcoding the name is a problem, but it's not. The only reason you need our is because you hardcoded the name in the print. For example,
whether ExistingPackage isuse strict; use warnings; package Hack; sub slash { my $var_ref = do { no strict 'refs'; \${'ExistingPackage::var'} }; $$var_ref = 'bar'; } package main; ExistingPackage->print_it(); Hack->slash(); ExistingPackage->print_it();
oruse strict; use warnings; package ExistingPackage; our $var = 'foo'; sub print_it { print("$var\n"); } 1;
package ExistingPackage; $var = 'foo'; sub print_it { print("$var\n"); } 1;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: symbol table vs. eval
by raflach (Pilgrim) on Feb 23, 2006 at 19:23 UTC | |
by ikegami (Patriarch) on Feb 23, 2006 at 19:37 UTC |