On Thu, May 17, 2001 at 09:03:33AM +0100, Alberto Manuel Brandao Simoes wrote:
> 
>       Hellows
> 
>       I'm writing a module and, as all modules should be, I'm using strict.

I trust you've got warnings turned on too.

>       So, I need to 'declare' every variable. What I want, is to do
>       something like:
> 
>       $varname = "myvar";
>       @$varname = ('a','b','c');
> 
>       This sets @myvar as I want, but how can I do this with strict??

You can't.  You are trying to use symbolic references and when you have
strict turned on you are promising not to do that.

>       my $varname = "myvar";
>       my @$varname = ('a','b','c');
> 
>       This does not works.

Exactly.  Why do you want to use this style?  In almost all cases such
as this it is better to use a hash.

  my %hash;
  $hash{myvar} = [qw( a b c )];

Ok, so you have a reference to an array rather than the array, but
that's no problem, right?

If you really must use symbolic references, you'll have to turn off
strict refs for a bit.  You'll also have to use package variables as
lexical variables (declared with my) are not in the symbol table.

my $varname = "myvar";
{
    no strict "refs";
    no strict "vars";
    @$varname = ('a','b','c');
}

Urg.  Just say no.  I'll guarantee you can find a better way.

perldoc strict
perldoc perlref

-- 
Paul Johnson - [EMAIL PROTECTED]
http://www.pjcj.net

Reply via email to