in reply to Five Ways to Reverse a String of Words (C#, Perl 5, Perl 6, Ruby, Haskell)
sub reverseWords { "@{[reverse split' ',shift]}" }
<update>
and without split -
sub reverseWords { "@{[reverse shift=~/\S+/g]}" }
</update>
--shmem
_($_=" "x(1<<5)."?\n".q·/)Oo. G°\ / /\_¯/(q / ---------------------------- \__(m.====·.(_("always off the crowd"))."· ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Five Ways to Reverse a String of Words (C#, Perl 5, Perl6, Ruby, Haskell)
by bart (Canon) on Dec 13, 2006 at 11:12 UTC | |
by shmem (Chancellor) on Dec 13, 2006 at 11:37 UTC | |
by bart (Canon) on Dec 13, 2006 at 11:48 UTC | |
by shmem (Chancellor) on Dec 13, 2006 at 11:56 UTC | |
by Anonymous Monk on Dec 13, 2006 at 16:01 UTC |