SPUG: Array Naming Question

Cantrall, Christopher W christopher.w.cantrall at boeing.com
Wed Feb 4 10:13:09 CST 2004

Also, MJD has an article on this subject.  http://perl.plover.com/varvarname.html


The real root of the problem code is: It's fragile. You're mingling unlike things when you do this. And if two of those unlike things happen to have the same name, they'll collide and you'll get the wrong answer. So you end up having a whole long list of names which you have to be careful not to reuse, and if you screw up, you get a very bizarre error. This is precisely the problem that namespaces were invented to solve, and that's just what a hash is: A portable namespace.


The real problem is that if your string contains something unexpected, it will sabotage a totally unrelated part of the program, and then you will have one hell of a time figuring out the bug.


MJD has 3 articles on this.  Quite interesting.


Chris Cantrall, Structural Engineer, 777
    Christopher.W.Cantrall at Boeing.com
  chris at cantrall.org

> -----Original Message-----
> From: Jeremy G Kahn [mailto:kahn at cpan.org]
> Sent: Wednesday, February 04, 2004 7:53 AM
> To: North, Walter
> Cc: spug
> Subject: Re: SPUG: Array Naming Question
> 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.
> --jeremy
> 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
> >as
> >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
> >
> >  
> >
> _____________________________________________________________
> 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