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

Re^2: Five Ways to Reverse a String of Words (C#, Perl 5, Perl 6, Ruby, Haskell)

by eyepopslikeamosquito (Canon)
on Dec 21, 2006 at 02:17 UTC ( #591025=note: print w/ replies, xml ) Need Help??


in reply to Re: Five Ways to Reverse a String of Words (C#, Perl 5, Perl 6, Ruby, Haskell)
in thread Five Ways to Reverse a String of Words (C#, Perl 5, Perl 6, Ruby, Haskell)

My awk is very rusty too. Unfortunately, your version emits a trailing space, which violates the spec. I've remedied that below and done it in the form of a function so that it can be more easily compared with the other languages.

# File : revwords.awk # Run with : awk -f revwords.awk </dev/null END { print reverseWords(" one two three four ") } function reverseWords(s) { if ((i = split(s, words)) == 0) return "" sret = words[i] while (--i > 0) sret = sret " " words[i] return sret }


Comment on Re^2: Five Ways to Reverse a String of Words (C#, Perl 5, Perl 6, Ruby, Haskell)
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (8)
As of 2014-09-02 11:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (21 votes), past polls