http://www.perlmonks.org?node_id=1150588


in reply to Derive a variable name from a variable?

there is another way,
but that is a path to the dark side of the force
@names = qw/adam jake john betty/; @adambooks = qw/ad_1 ad_2/; @jakebooks = qw/ja_1 ja_2/; for $n (@names){ print "$n:\n"; print "\t@{$_}\n" for $n."books"; }

there might be some jedi,
who'd tell you that it's wrong
they just want you to obey their will

Replies are listed 'Best First'.
Re^2: Derive a variable name from a variable?
by LanX (Sage) on Dec 21, 2015 at 15:51 UTC
    This is only half the answer because using strict is a standard nowadays.

    There might be cases where this is needed, but please apply no strict "refs" in a restricted block around it and use strict; in file scope.

    see for instance no strict refs for blocks?

    > there might be some jedi,

    > who'd tell you that it's wrong

    > they just want you to obey their will

    Perl has no taboos, just best practices.

    Cheers Rolf
    (addicted to the Perl Programming Language and ☆☆☆☆ :)
    Je suis Charlie!

Re^2: Derive a variable name from a variable?
by mavericknik (Sexton) on Dec 18, 2015 at 21:25 UTC
    Haha I would've been seduced by the dark side if it weren't for the wisdom of the monks here!
      ^_^