http://www.perlmonks.org?node_id=887163

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?