While I agree with the premise of this article, I've objected in the past to
sending people there to learn about the pitfalls of the so-called
"dynamically named variables".  In general, if you want to convince someone
of something, you don't tell them that they're stupid for wanting to do it.
It's argumentative and not conducive to getting your point across.
Especially when it's a logical leap for most people that is quite intuitive,
even though it is a VERY BAD IDEA.  Better to lead people down the right
path than insult them outright.

-----Original Message-----
From: Jeff 'japhy' Pinyan [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, April 30, 2002 8:47 AM
To: David Gray
Cc: [EMAIL PROTECTED]; [EMAIL PROTECTED]
Subject: RE: array numerical name...


On Apr 30, David Gray said:

>> Hi all - should be simple - but I cannot figure it out
>> 
>> basically i want to name an array with  a subscript ie 
>> world0[0] and world1[0]   the 0/1 being a variable, i have tried to
>>  produce a simple example....
>> 
>> For any help - thanks..
>> ----------------------------------------------------------
>> @fred = "one,two,three,four";
>> 
>> $a=0;
>> 
>> @array$a=split(/,/, @fred)
>> 
>> for ($b=0;$b<4;$b++) {
>> print @array$a[$b];
>> }
>
>Just FYI, it is possible to do that, like so:

NO!  Don't teach how to do this, please.  It can lead to security problems
in your program; it also leads to having an unknown number of variables,
and possibly, variables with names you don't know.

Mark-Jason Dominus has an article about why using a variable as a name for
a variable is a bad idea.  Symbolic references are a left-over artifact
from The Land Before Perl 5.  They are wizardry, and should be avoided
99.9% of the time.  There's about ONE place where you should use them, and
even then, you probably don't need to.

  http://perl.plover.com/varvarname.html

-- 
Jeff "japhy" Pinyan      [EMAIL PROTECTED]      http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
** Look for "Regular Expressions in Perl" published by Manning, in 2002 **
<stu> what does y/// stand for?  <tenderpuss> why, yansliterate of course.
[  I'm looking for programming work.  If you like my work, let me know.  ]


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to