Enjoy! **UPDATED BASED ON REPLIES#!usr/bin/perl while(<>) { chomp; s/\s//g; #Remove whitespace within the line $leng = length($_); $count = -1; while ($count < ($leng - 1) ) { $count ++; $char = substr($_,$count, 1); push @list, $char; #Push one letter into the array } } print "@list\n"; my @list2; while ( $#list2 < $#list) { $randint = int(rand($#list+1)); redo if $list[$randint]=~" "; push @list2, $list[$randint]; $list[$randint]=" "; } print "@list2\n";
Thanks for all the great ideas!#!usr/bin/perl push @list, grep{/\S/} split '' while <>; print "@list\n"; my @list2; while (@list){ $randint = int(rand($#list+1)); push @list2, splice @list, $randint, 1; } print "@list2\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Array Fun
by bart (Canon) on Apr 06, 2007 at 11:06 UTC | |
by phantom20x (Acolyte) on Apr 06, 2007 at 18:00 UTC | |
|
Re: Array Fun
by wfsp (Abbot) on Apr 06, 2007 at 10:38 UTC | |
by phantom20x (Acolyte) on Apr 06, 2007 at 17:50 UTC | |
by xiaoyafeng (Deacon) on Apr 19, 2007 at 03:57 UTC | |
|
Re: Array Fun
by jwkrahn (Abbot) on Apr 18, 2007 at 13:49 UTC |