Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Re^2: REGEX Non-Destructive Flag

by mmartin (Monk)
on Jan 10, 2012 at 17:54 UTC ( #947203=note: print w/ replies, xml ) Need Help??

in reply to Re: REGEX Non-Destructive Flag
in thread REGEX Non-Destructive Flag

Hey toolic, thanks for the reply.

Ok I was afraid of that... Thanks

Is there an easier way (less lines) that I could use with my version like my previous example (i.e. $str = $str2 =~ s/pattern/replace/r; ).

The only way I can think to do this without changing the original string is:

my $str1 = "How-Are-You-Doing" my $str2 = $str1 $str2 =~ s/-/ /; print $str2; ____OUTPUT____ Hello How Are You Doing


Comment on Re^2: REGEX Non-Destructive Flag
Download Code
Replies are listed 'Best First'.
Re^3: REGEX Non-Destructive Flag
by MidLifeXis (Monsignor) on Jan 10, 2012 at 18:08 UTC

     perl -ne '(my $foo = $_) =~ s/-/ /g;'

    The assignment returns an lvalue which then gets the substitution run on it. Basically the same as yours, just in one statement.


Log In?

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (8)
As of 2015-11-27 13:50 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (729 votes), past polls