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?

$s = 'Two words'; $s =~ s[(^\S+)(\s.*\s)(\S+$)][$3$2$1]; print $s; #Two words

Oops! ;-)

  • 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 (Patriarch) on Mar 11, 2007 at 13:32 UTC

    The OP asked for help, not a perfect solution. S'always good to leave a little something for them to do themselves. It encourages people to try and understand the help provided, rather than just using it verbatim.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.