bazi has asked for the wisdom of the Perl Monks concerning the following question:
In the module I planned to give a life to a global variable on the top of the module and use it across all subs/methods as follows:$ENV{"VER"} = "3.0";
$ENV{"VER"} however is undef at this stage yet. I would need to actually use it in subs/methods wherever I need to resolve path. It does seem to work in this way although that would cause me some real pain. Other way I thought of was to declare $ver_dir, as global var, as follows:my $ver_dir = "/opt/SAT/" . $ENV{"VER"};
wherea set_root_dir would be:my $ver_dir = set_ver_dir();
Though such trick for making global vars within a module a result of one of module's sub does not seem to work. Any suggestions? Mind, tha I would NOT like to have it hardcoded in the module. Nor use any symlinks such us /opt/SAT/live or /opt/SAT/current that would point to the correct version on the file system.sub set_ver_dir { my $path = $FindBin::Bin; $path =~ /\opt\/SAT\/(\d*\.\d*)\//; my $ver = $1; return "/opt/SAT" . $ver }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: dynamiclly assigning values to global variables in modules
by NetWallah (Canon) on Mar 28, 2014 at 02:53 UTC | |
|
Re: dynamiclly assigning values to global variables in modules
by CountZero (Bishop) on Mar 28, 2014 at 06:47 UTC | |
|
Re: dynamiclly assigning values to global variables in modules
by tobyink (Canon) on Mar 28, 2014 at 10:01 UTC | |
|
Re: dynamiclly assigning values to global variables in modules
by Anonymous Monk on Mar 28, 2014 at 05:54 UTC | |
|
Re: dynamiclly assigning values to global variables in modules
by Laurent_R (Canon) on Mar 28, 2014 at 07:22 UTC | |
|
Re: dynamiclly assigning values to global variables in modules
by Anonymous Monk on Mar 28, 2014 at 09:09 UTC | |
|
Re: dynamiclly assigning values to global variables in modules
by locked_user sundialsvc4 (Abbot) on Mar 28, 2014 at 12:50 UTC |