daemonchild has asked for the wisdom of the Perl Monks concerning the following question:

<html> <body> I am in the process of writing a script to monitor the various logs on my system.
I would like to generate variables in the form

$server_service_path

where server and service are variables inputted to the script.

eg. $megatron_ftp_path = "my/path/to/log";

any takers? would be much appreciated. </body> </html>

Replies are listed 'Best First'.
Re: possible newbie question
by btrott (Parson) on May 18, 2000 at 22:35 UTC
    I would recommend against doing that. Use a hash instead, something like this:
    $paths{megatron}{ftp} = "/foo/megatron/ftp"; $paths{megatron}{http} = "/foo/megatron/http";
    Does that make sense? You're much better off using a multi-dimensional hash like this, rather than using symbolic references (which is what you'd be doing).
      <html> <body>
      that makes a lot of sense actually ...

      much thanks
      </body> </html>

Re: possible newbie question
by princepawn (Parson) on May 18, 2000 at 22:21 UTC
    1: Use a descriptive title so that others in the same quandry can refer to your msg by title and find it 2: I really dont know what you are saying, but this may work
    $path{megatron}{ftp}='/path/1'; $path{otherron}{http}='/path/2'; $server = shift && $service = shift || die "must input server and service"; $variable_name = "${server}_${service}_path"; $$variable_name = $path{$server}{$service};
      thanks

      i guess i got so hung up on the first way i tried to do it i forgot about hash arrays
      : )

Re: possible newbie question
by c-era (Curate) on May 18, 2000 at 22:30 UTC
    I'm not sure what exactly you want, but you can try this:
    $server="server"; $service="service"; $var = "$server_$service"."_path"; $code="\$$var='my/path';print \"\$$var\n\""; eval ($code);