in reply to substitution in a string

Here's an in-place edit:
s/([^=]+)/(my $lhs=$1) =~ tr:_:.:; $lhs/e for @envArray;
Making it work on a copy is just a matter of
s/([^=]+)/(my $lhs=$1) =~ tr:_:.:; $lhs/e for @array=@envArray;

Caution: Contents may have been coded under pressure.

Replies are listed 'Best First'.
Re^2: substitution in a string
by Roger_B (Scribe) on Sep 28, 2005 at 13:32 UTC
    One problem with this - it will substitute . for _ in all environmental variables.

    How about

    /^(?i:ORACLE_SID|ORACLE_HST_SID|ORACLE_HOME|SDP_HOME)=/ && s/([^=]+)/(my $lhs=$1) =~ tr:_:.:; $lhs/e for @envArray;

    Roger

    update: better idea by Roy Johnson below. Doh!

    However his code doesn't actually work because the brackets are the (?imsx-imsx:pattern) extension. Below is a possible fix:

    s/^((?i)ORACLE_SID|ORACLE_HST_SID|ORACLE_HOME|SDP_HOME)(?==)/(my $lhs=$1) =~ tr:_:.:; $lhs/e for @envArray;

      There's really no need to do a separate match and substitution, just change the pattern that the substitution matches:
      s/^((?i:ORACLE_SID|ORACLE_HST_SID|ORACLE_HOME|SDP_HOME))(?==)/(my $lhs +=$1) =~ tr:_:.:; $lhs/e for @envArray;
      (update: corrected the missing parens, as per Roger_B's update)

      Caution: Contents may have been coded under pressure.