Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

Re: Read UNIX environment variable

by fisher (Priest)
on Feb 09, 2011 at 10:33 UTC ( #887165=note: print w/replies, xml ) Need Help??

in reply to Read UNIX environment variable

like this?
use Env; my $n = $ENV{'NOTEUSERS'}; for (split /[\s\n]/, $n) {print "key: \"$_\"\n" if ($_)}
Can you improve this and show here your result?

Replies are listed 'Best First'.
Re^2: Read UNIX environment variable
by DrHyde (Prior) on Feb 09, 2011 at 10:57 UTC
    An obvious improvement is to notice that \s contains \n. And also that 'use Env' is completely useless in this case.
      Well, thank you, captain.
      Thanks, will I be able to access env variables if my perl code gets run from cron?

        Yes and no.

        You can read an environment, but as cron jobs run their own environment, you need to load the environment you want. See Get default login environment.

        You can access environment variables in a script run as a cron job but take note that cron jobs often have only a sub-set of the environment available to a user shell. For instance, you will likely have a minimal $PATH under cron. It might be worth writing a small script to dump the environment to a file then run it as a cron job to see what's available.

        I hope this is helpful.



Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://887165]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2020-11-27 11:18 GMT
Find Nodes?
    Voting Booth?

    No recent polls found