Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^4: How do I reverse the order of the first and last word of a string?

by w-ber (Hermit)
on Mar 11, 2007 at 07:23 UTC ( #604189=note: print w/replies, xml ) Need Help??


in reply to Re^3: How do I reverse the order of the first and last word of a string?
in thread How do I reverse the order of the first and last word of a string?

You may want to fix that to properly handle punctuation and capitalization:

$_ = 'This is the word.'; $_ =~ s[(^\w+)(\s.*\s)(\w+)([[:punct:]]?)$][\u$3$2\l$1$4]; print

--
print "Just Another Perl Adept\n";

  • Comment on Re^4: How do I reverse the order of the first and last word of a string?
  • Download Code

Replies are listed 'Best First'.
Re^5: How do I reverse the order of the first and last word of a string?
by BrowserUk (Pope) on Mar 11, 2007 at 08:00 UTC

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (5)
As of 2016-10-01 23:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?






    Results (9 votes). Check out past polls.