Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have a perl file that want to understand certain environmental variables. So I can add:

$ENV{PLACK_ENV} = 'development'

in the code and its ok.

But is there a way to do this without touching the code?

ps: I'm working with linux

share|improve this question
I am not sure I understand your question. Are you asking if you can set environment variables without using Perl ? – Hunter McMillen 21 hours ago
@HunterMcMillen Yes. I do not want to touch the perl code because i have 2 sets of environmental variables, for development and deployment. So I dont want to have things like "$ENV{PLACK_ENV}='development'" inside the code. – adriancdperu 21 hours ago
1  
You can easily set environment variables within your shell. Inside your .bashrc or .bash_profile. – Hunter McMillen 21 hours ago

1 Answer

up vote 5 down vote accepted

You can do this easily

$ export PLACK_ENV=development
$ perl your_script.pl

or

$ PLACK_ENV=development perl your_script.pl
share|improve this answer
Thanks @Taras that certainly works but what if I work with modules? Say A.pm needs development and B.pm needs A.pm. If I run A.pm as PLACK_ENV=development perl A.pm and then run PLACK_ENV=development perl B.pm, B does not get the environmental variables. – adriancdperu 20 hours ago
Sorry, B.pm does get them! – adriancdperu 20 hours ago
yw! Anyway, if you do export PLACK_ENV=development, all scripts and their modules you run in current shell will see this env variable. If you don't want to export this variable each time, you can just put that line to your ~/.bashrc ( as recommended above ). – Taras 20 hours ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.