Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Read UNIX environment variable

by Anonymous Monk
on Feb 09, 2011 at 10:20 UTC ( #887163=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

In unix I have an env variable like this
NOTEUSERS=" me@us.com \ them@us.com\ " export NOTEUSERS
Yes there are spaces at the front. I can read this using
use Env; my @noteusers = $NOTEUSERS;
How can I split this up so that each entry of @noteusers array is just the email address without spacing etc. Thanks

Replies are listed 'Best First'.
Re: Read UNIX environment variable
by fisher (Priest) on Feb 09, 2011 at 10:33 UTC
    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?
      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?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://887163]
Approved by marto
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2021-01-24 04:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?