in reply to Re: printing enviroment vars from regex
in thread printing enviroment vars from regex

 $_ =~ s/\$(\w+)/$ENV{$1}/g
I'm pretty sure you want:  0 while $_ =~ s/\$(\w+)/$ENV{$1}/;

Replies are listed 'Best First'.
Re^3: printing enviroment vars from regex
by Limbic~Region (Chancellor) on Aug 01, 2004 at 19:46 UTC
    BUU,
    Well saying that without an explanation doesn't help me much. Of course it is possible it should be obvious to me why - but I am dense (to be read it is the weekend). It worked fine for my sample input - what advantages does yours have over mine?

    Cheers - L~R

      His version will do nested replacements, eg if $FOO expands to the text $BAR, then that will in turn be expanded as well. I don't know if that's particularly desirable, though.

      Makeshifts last the longest.

        Aristotle,
        BUU and I discussed this over in #perl independent of these posts. I understand what his version is doing but I think that is the "wrong" thing to do.
        $ FOO="asdf" $ BAR="$FOO you" $ echo $BAR asdf you $ FOO=123 $ echo $BAR asdf you
        There is only one level of expansion in environmental variables so I would assume that is what is intended for this script. I did make the caveat that it was fragile with regards to the assumptions I made and that it would have to be modified accordingly.

        Cheers - L~R