0

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

3
  • I am not sure I understand your question. Are you asking if you can set environment variables without using Perl ? Commented Jun 10, 2013 at 3:23
  • @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. Commented Jun 10, 2013 at 3:25
  • 1
    You can easily set environment variables within your shell. Inside your .bashrc or .bash_profile. Commented Jun 10, 2013 at 3:27

1 Answer 1

7

You can do this easily

$ export PLACK_ENV=development
$ perl your_script.pl

or

$ PLACK_ENV=development perl your_script.pl
Sign up to request clarification or add additional context in comments.

3 Comments

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.
Sorry, B.pm does get them!
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 ).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.