Beefy Boxes and Bandwidth Generously Provided by pair Networks vroom
P is for Practical
 
PerlMonks  

Re^2: substitution in a string

by Roger_B (Scribe)
on Sep 28, 2005 at 09:32 UTC ( [id://495730]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to Re: substitution in a string
in thread substitution in a string

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;

Replies are listed 'Best First'.
Re^3: substitution in a string
by Roy Johnson (Monsignor) on Sep 28, 2005 at 10:36 UTC
    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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://495730]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.