Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

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

by Hue-Bond (Priest)
on Sep 09, 2008 at 21:55 UTC ( [id://710203]=note: print w/replies, xml ) Need Help??


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

No bash solution yet, so here it goes (pure bash, no external binaries):

STR=" one two three four " ARR=($STR) LEN=${#ARR[*]} LAST=$(($LEN-1)) ARR2=() I=$LAST while [[ $I -ge 0 ]]; do ARR2[ ${#ARR2[*]} ]=${ARR[$I]} ## push I=$(($I-1)) done echo ${ARR2[*]}

--
David Serrano

  • Comment on Re: 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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://710203]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2024-04-24 19:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found