in reply to Symbolic references disallowed

Others told you how you should do it, so I'll just explain the error. When you say @$array, you're saying, "the array pointed to by the reference contained in $array." Since your $array contains a text string instead of an array reference, the fallback (Perl 4) way to handle that would be to use the value of the scalar as the name of the array, giving you @TEST in this case. However, this is ugly and dangerous, so strict refs does not allow it.

Aaron B.
My Woefully Neglected Blog, where I occasionally mention Perl.

Replies are listed 'Best First'.
Re^2: Symbolic references disallowed
by davido (Cardinal) on Apr 18, 2012 at 20:25 UTC

    I would substitute "ugly and dangerous" with "easily abused in ways that lead to buggy and unmaintainable code." Beauty is in the eye of the beholder, and the real danger is misuse, rather than simply use in general.

    I upvoted your node, because it did a nice job of explaining one way of creating a symbolic reference, and offered words of caution. But most of all, because you explained "strict 'refs'" rather than just repeating the tired mantra of "use strict;", with no mention of the specific aspect of strictures that targets this coding practice.

    Maybe you've already read MJD's article, here: Why I Hate strict (part of a series of twelve lightning talks). If not, you might find it interesting.


    Dave