Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Case-preserving substitutions

by jryan (Vicar)
on Jan 18, 2002 at 13:03 UTC ( #139773=note: print w/replies, xml ) Need Help??


in reply to Case-preserving substitutions

You need the /e modifier to cause the right side interpolation of the variable:
s/\b($old)\b/(lcfirst($1) eq $1) ? lcfirst($new) : ucfirst($new)/gei;
Consult perlman:perlre for more details.

Update:
I think I may have mis-interpreted the question. It has been since corrected, and the difference turned out to be slight.

Replies are listed 'Best First'.
Re: Re: Case-preserving substitutions
by giulienk (Curate) on Jan 18, 2002 at 13:14 UTC
    Update: by the time i posted this, jryan updated his post correctly :)

    You also need the "i" modifier in the end, to match case-insensitive way.

    $|=$_="1g2i1u1l2i4e2n0k",map{print"\7",chop;select$,,$,,$,,$_/7}m{..}g

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://139773]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2023-12-08 02:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your preferred 'use VERSION' for new CPAN modules in 2023?











    Results (35 votes). Check out past polls.

    Notices?