wood burning stoves*
The moose likes Perl and the fly likes env variables Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Languages » Perl
Bookmark "env variables" Watch "env variables" New topic
Author

env variables

D Preethi
Ranch Hand

Joined: May 24, 2008
Posts: 68
Hi All,

Does anyone know how to check if a environment variable is set or not from inside a perl script?

- Preethi
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 10906
    
  12

Perl has a special associative array created by default, called ENV. So, if you want the PATH, you can do this:

If you want to see a list of all your variable and their values, a loop would look like this:

to see if it's defined or not, just test it:


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
James Sabre
Ranch Hand

Joined: Sep 07, 2004
Posts: 781

There is an exists() function that can be applied to any associative array. For example to check for the existence of a particular environment variable :-


Just checking the value $ENV{"SOME_NAME"} will not tell you if the environment variable is set since the result will be the same for not set as for it being set but empty. Does the distinction matter to you? If not then just get the value and test it. If so then use exists().


Retired horse trader.
 Note: double-underline links may be advertisements automatically added by this site and are probably not endorsed by me.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: env variables
 
Similar Threads
Home loans in India - fixed or floating ?
Why Java ?
Dont declare global variables in Servlet
regard on k&b book
WA #1.....word association