in reply to Re: Importing dynamic variables
in thread Importing dynamic variables

This whole idea makes me want to throw my hands in the air and run out of the room screaming as though my hair were on fire
I knew that would be the response when I posted! Still, I'm curious to know how to get this to work.
It should not be "use gen_var($one);", but rather, "use gen_var qw( one );"
But wouldn't that import the subroutine "one" and not the variable "$one"?
As long as you're doing this, wouldn't it be easier to directly manipulate the symbol table as a hash?
I did try that accessing the symbol table. Say each variable was an object and not a scalar
package gen_var; use banana; my @variables = qw(one two three); my $counter = 1; foreach my $variable (@variables) { no strict; *$variable = banana->new($counter++) } 1;
and from the classing package:
use gen_var; $one->get_counter();
That doesn't work, but I'm not sure how to fix it...

Replies are listed 'Best First'.
Re^3: Importing dynamic variables
by Anonymous Monk on Nov 17, 2006 at 00:30 UTC
    Ah,
    package gen_var; use banana; my @variables = qw(one two three); my $counter = 1; foreach my $variable (@variables) { no strict; my $ns_var = caller() .'::'.$variable; *$ns_var = \banana->new($counter++); } 1;
    should work
      Except it doesn't if I use strict. Any ideas?
        Uh, yeah, it's not supposed to work if you use strict. That's the whole point. Stop doing it.