irata73 has asked for the wisdom of the Perl Monks concerning the following question:

Hi, the script:
use strict; use Data::Dumper; { my( $key ) = 'Statistic::Test'; my( $val ) = [ 1, 2, 3, 4 ]; { no strict 'refs'; ${$key} = $val; } print Dumper( $Statistic::Test ); }
outputs
Name "Statistic::Test" used only once: possible typo at ref.pl line 12 +. $VAR1 = [ 1, 2, 3, 4 ];

Is there another way than using "no warnings 'once'" to avoid the "used only once" warning?

Thanks for your help!

Replies are listed 'Best First'.
Re: "used only once" for symbolic references
by Athanasius (Cardinal) on Jul 28, 2015 at 12:31 UTC
Re: "used only once" for symbolic references
by stevieb (Canon) on Jul 28, 2015 at 12:31 UTC

    Please read this entertaining and informative three-part story by Mark-Jason Dominus on the matter.

    You're much safer to use a hash to do this trickery, as that's what it was designed for.

    my %hash; $hash{Statistic::Test} = [qw(1 2 3 4)]; print Dumper \%hash;

    -stevieb

Re: "used only once" for symbolic references
by Anonymous Monk on Jul 28, 2015 at 10:58 UTC

    irata73: Is there another way than using "no warnings 'once'" to avoid the "used only once" warning?

    This type of question is frequently asked; If you can't find the answer yourself, should you be really using this construct?