SPUG: Array Naming Question

Jeremy G Kahn kahn at cpan.org
Wed Feb 4 09:52:40 CST 2004

This is a good question, and a FAQ if you know where to look. The FAQ 
has an explanation for how you might want to go about doing this, and 
why it's probably a bad idea, and some suggestions for alternatives:

perldoc -q 'variable name':

Found in /usr/share/perl/5.8.2/pod/perlfaq7.pod
       How can I use a variable as a variable name?

               Beginners often think they want to have a variable
               contain the name of a variable.

                   $fred    = 23;
                   $varname = "fred";
                   ++$$varname;         # $fred now 24

               This works sometimes, but it is a very bad idea
               for two reasons.

               The first reason is that this technique only works
               on global variables.  That means that if $fred is
               a lexical variable created with my() in the above
               example, the code wouldn't work at all: you'd

Hope that's useful.


North, Walter wrote:

>Good Morning all,
>Maybe this is a dumb question, but here goes anyway:
>Does anyone know if it possible to include a variable in, or use a variable
>the name of an array or hash, and if so how would one do it?
>thanks in advance.
>Walter North 406-444-2914 
>Operating Systems Programmer 
>wnorth (at) state (dot) mt (dot) us
>Seattle Perl Users Group Mailing List  
>POST TO: spug-list at mail.pm.org  http://spugwiki.perlocity.org
>ACCOUNT CONFIG: http://mail.pm.org/mailman/listinfo/spug-list
>MEETINGS: 3rd Tuesdays, U-District, Seattle WA
>WEB PAGE: http://www.seattleperl.org

More information about the spug-list mailing list