laziness, impatience, and hubris | |
PerlMonks |
Re: How to set (environment) variables for the scriptby mr_mischief (Monsignor) |
on Jun 10, 2010 at 13:48 UTC ( [id://844009]=note: print w/replies, xml ) | Need Help?? |
That actually works, but I think it'd be arguably cleaner if you're just setting variables in your shell script to write some Perl to parse the variables out of the script. Currently you're looking at one exec to get the Perl code running. If your environment isn't already set, you're looking at exec'ing another shell, which then reads your shell script for inclusion and execs another perl. It's conceptually pretty simple, but it's going to be tricky to follow in the process tree should you need to do so sometime. Compare that to something like this:
If you're running programs from within your shell script to set the environment rather than just setting variables, then I'd stick with what you have. Execing a few more times is a drawback, but it's a tiny one. It would be preferable to additional maintenance if your variable parser got any fancier than the one above. I still question the use of a separate flag variable to let you know the environment is set up even when using the shell, but that's more of a personal preference. Other things to consider are whether you have any variables that need to be set prior to perl launching rather than after and whether you're using any of the variables that perl would need to have set as environment variables rather than just reading them into a Perl option hash.
In Section
Seekers of Perl Wisdom
|
|