in reply to Re: using input as array name
in thread using input as array name

excellent suggestions etc but the tricky bit of the question is how to call this perl script from command line to request this particular HoA (names) or another, e.g. birthdates.
without coding this myself, I suggest that part of the solution would be to use one of the standard args modules, which provides a nice mechanism to supply and parse zero or more args to perl in any order/combination. anyway, something possibly to consider. the harder bit of not passing symbolic reference can be done by testing the value supplied to the perl script against possible requests in a switch e.g.
my $request = shift; switch($request) { case 'names' print @names; case 'birthdays' print @birthdays; else print 'unknown request`; }
and so forth. if as in my example the names and birthdays are parts of a proper record set and related, e.g. person 1 -> birthday 1, then a slightly more elaborate structure can be created with a hash etc.
in any case, using such switch or even if statements obviates need to use directly the value of one variable as a symbolic link to another variable.
the hardest line to type correctly is: stty erase ^H

Replies are listed 'Best First'.
Re^3: using input as array name
by calmthestorm (Acolyte) on Oct 14, 2010 at 21:55 UTC
    Excellent suggestion, wonder why I never thought of using a case statement in a perl script.. All of this is academic at point as I disabled the strict refs as per the first suggestion and now my script is working as required/expected. The reason I felt it necessary to do this in the first place is to allow my monitoring system to run external commands against multiple pre-defined hosts in attempts to "self-heal" certain problems. Once again, thank you everyone for your input and suggestions.
      If the switch would get too much to maintain, if there are many cases, then you could do a similar thing with a hash, with the command line arg being the key in the hash. as far as i know this is not a bad thing to do, as you're not using the arg to construct a variable name as such.
      you mention using external commands to "heal" hosts. from a systems engineer point of view, this is quite dangerous, unless you can categorically rule out all other possibilities for causing a particular pattern of behavior by the hosts. and said patterns sometimes unexpectedly change etc. so plenty of defensive programming is usually necessitated. and be prepared for this kind of thing never being 100%, as it can sometimes cause more problems than it fixes.
      anyway, have fun
      the hardest line to type correctly is: stty erase ^H