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

I'm following one of the answers to Forced resolution of environment variables in order to create a small sub to manage incoming data containing environment variables, but I seem to get the error "use of uninitialized value in substitution iterator". From http://www.sitepoint.com/forums/printthread.php?threadid=114018, I can understand the problems around changing $_ inside a sub, and have adjusted my code accordingly (I think!), but I can't see what else I need to change to get the substitution to work. Anyway, here's the code...
sub sub_env { my($in_string)=@_; $in_string =~ s/\$([A-Z0-9_]+)/$ENV{$1}/g; return $in_string; }
Thanks for your help.

Replies are listed 'Best First'.
Re: use of uninitialized value in substitution iterator
by borisz (Canon) on Nov 11, 2004 at 11:40 UTC
    try:
    s/\$([A-Z0-9_]+)/$ENV{$1}||''/eg;
    or whatever you like to do if the environment var is not there.
    Boris
      OK, so it was a "null return" from the environment hash, not something to do with $_? I guess that makes more sense.

      Thanks.