Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

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

by jonadab (Parson)
on Mar 11, 2007 at 11:35 UTC ( #604212=note: print w/replies, xml ) Need Help??


in reply to Re^2: 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?

my @chunks = split /(\s+)/, $str;

I prefer not to throw anything away in such cases:

my @chunk = split /(?<=\b)(?=\w)/, $str;

Of course this complicates the code for reversing a word, as you have to keep the trailing whitespace at the end (which can be accomplished with sort if you're careful), but it also means that if the original has two spaces after a word, your final result will too!

-- 
We're working on a six-year set of freely redistributable Vacation Bible School materials.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://604212]
help
Chatterbox?
[Corion]: Hmmm... Weird. Maybe it needs that for doing its timers or something. Still weird.
[Corion]: But I guess I'll find out soonish, as my application seems to use Prima for more than just displaying the OpenGL output soonish ;))
[ambrus]: No, I think the timers are handled fine in the event loop, as far as I can see.
[Corion]: So far, I liked Prima quite well as it simply seems to do what I want even if it has an upside-down coordinate system. But it installs from CPAN out of the box and is cross-platform

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (6)
As of 2016-12-09 10:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (150 votes). Check out past polls.