Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
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 ( #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
Node Status?
node history
Node Type: note [id://710203]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (16)
As of 2014-09-23 15:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (227 votes), past polls