Care to expound? What is dangerous about the first example? What's
with the "hash" in the second? As I understand it, there was no hash
involved - it was the name of a scalar variable stored as a string in
another scalar. Is hash a keyword or simply a variable name? If this
is a FAQ or a perldoc question, a pointer to the right location would
be appreciated. I don't find anything looking there and a Google for
$hash doesn't show up anything that seems relevant.
Okay, I take it back, Uri.
Dan:
It is a FAQ; pointers to the FAQ are posted here regularly, and can
be found by a quick google search, or (iirc) at rtfm.mit.edu.
In short: using a hash instead of variable-names-as-a-variable is far
superior for several reasons. The hash is neater (it's one data
structure instead of multiple); it encapsulates the data in one neat
package, and allows it to be hidden better within a subroutine or an
object (insofar as Perl allows data to be hidden) (Encapsulation and Data
Hiding are two important concepts in modern computer science); the
variable-name approach can often lead to hard-to-find bugs due to typos
and bad logic.
No experienced Perl programmer uses variables as variable names
except in those rare situations when no other approach will work.
(Better, Uri? ;-) )
--
Eric
`$=`;$_=\%!;($_)=/(.)/;$==++$|;($.,$/,$,,$\,$",$;,$^,$#,$~,$*,$:,@%)=(
$!=~/(.)(.).(.)(.)(.)(.)..(.)(.)(.)..(.)......(.)/,$"),$=++;$.++;$.++;
$_++;$_++;($_,$\,$,)=($~.$"."$;$/$%[$?]$_$\$,$:$%[$?]",$"&$~,$#,);$,++
;$,++;$^|=$";`$_$\$,$/$:$;$~$*$%[$?]$.$~$*${#}$%[$?]$;$\$"$^$~$*.>&$=`