In the spirit of offering good advice and then immediately undermining it, here's a way to do exactly what you asked about in your OP.
As already mentioned, symbolic referencing does not work with lexical (i.e., my) variables, but only with package (i.e., global) variables. Thus, the my @HD = ... ; statement of the OPed code becomes the our @HD = ... ; statement below (see our) pre-declaring and initializing the @HD array package variable. Pre-declaration of variables is one of the practices imposed by strict. Use of strict (and warnings) is highly recommended, especially for novice Perlers, so keep doing this.
Another restriction imposed by strict is that symbolic referencing is right out, so you have to turn off this particular stricture (i.e., 'refs'; see no) before using a symbolic reference. Strictures are lexical in scope, so turn off this restriction in the narrowest possible scope, leaving it in force in the rest of your code.
The other good point already made is that symbolic referencing is almost never needed. Dominus's Why it's stupid to `use a variable as a variable name' is another good discussion of the reasons why.
So at last, after all the good advice not to play with fireworks, here's a bunch of 'crackers and a box of matches and the stern admonition not to come crying to me if you lose a couple of fingers.
>perl -le
"use warnings;
use strict;
;;
our @HD = (0.153488905, 0.153488905, 3.688879454);
my $testing = 'HD';
{ no strict 'refs';
print @{$testing};
print qq{x @{$testing} y};
}
"
0.1534889050.1534889053.688879454
x 0.153488905 0.153488905 3.688879454 y
|