So why would one want to use them? Why are they available? (rhetorical question)
While playing with Perl (in an effort to learn it), I devised a subroutine that I found to be very useful. It's more complex than that shown here, but it's the same basic idea.
So, maybe there's another way to do the same thing, but, you know... tmtowtdi.
# Example of using variable names for variables, # that I find useful. #------------- # user defined code # ------------ my $some_var_list = var_from_env_var("list"); my $some_var_source = var_from_env_var("source"); my $some_var_other = var_from_env_var("other"); print "list=> $some_var_list\n". "source=>$some_var_source\n". "other=> $some_var_other\n"; # ------------ # my module # ------------ sub var_from_env_var { # could use this, or some other complex method # of determining the default value. my $list_def = $ENV{"LIST_VAR"} || $ENV{"LIST_VAR_DEPRECIATED"} || "other_list"; my $source_def = $ENV{"SOURCE_VAR"} || $ENV{"SECONDARY_SOURCE"} || "other_source"; # is there another way to use a variable to point # to a variable other than eval? my $input = shift; my $result = eval "\$$input"."_def"; return $result if (defined ($result)); return $input; }
In reply to variables names used to define variables by Sandy
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |