in reply to variables names used to define variables

In response to your second question, you don't need to eval. Use what's called a "symbolic reference" and do this:

# v Assign a variable name to the $result variable my $result = "${input}_def"; return $$result if (defined ($$result)); # ^dereferencing return $input
Check out perlref for more info.

BUT (big but...) you should be using "real" or "hard" references. Because in general, Symbolic refernces are just a bit too much power for us mortals to handle, because you can muck stuff up so easily. Check out perlref again, but this time look for hard references info. The truth is, you could do all of this with a hash and references. Good luck!



Who is Kayser Söze?
Code is (almost) always untested.

Replies are listed 'Best First'.
Re: Re: variables names used to define variables
by mugwumpjism (Hermit) on Dec 11, 2003 at 06:35 UTC

    If you're going to use symbolic references (and hey, why not, they're cool :-) ), at least make it really obvious what you're doing;

    # v Assign a variable name to the $result variable return ${"${input}_def"} || $input;

    I've been using symbolic references so much recently I've been getting int the habit of using `use strict "vars", "subs";' instead of just `use strict;' :-)

    $h=$ENV{HOME};my@q=split/\n\n/,`cat $h/.quotes`;$s="$h/." ."signature";$t=`cat $s`;print$t,"\n",$q[rand($#q)],"\n";