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

Re: Swapping two parts of a string

by GrandFather (Saint)
on Jul 22, 2007 at 20:53 UTC ( [id://628146]=note: print w/replies, xml ) Need Help??


in reply to Swapping two parts of a string

Capture the two strings to be swapped using a regex then put them back together in opposite order:

$origin =~ s/\( ([^ ,]+) \s*,\s* ([^ )]+) \) /($2 $1)/x;

Note that the /x allows the spaces to be used to break up the expression for easier understanding.


DWIM is Perl's answer to Gödel

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (2)
As of 2026-04-23 00:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    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.