On Tue, Jun 29, 1999 at 11:45:35PM +0100, Adam Sampson wrote: > On Tue, Jun 29, 1999 at 10:44:08PM +0100, Adam Sampson wrote: > > At some point I'll reimplement NIALL in Perl or Python; I suspect it could > > be done as a Perl one-liner. Any takers? > > OK, I got bored enough to do it. This is my third Perl program, so apologies > if it's insufficiently fun. It's also three lines rather than one (but I'll > accept improvements): > > while(<>){chomp;@i=split;$w{'>'}.=" ".$i[0];while($#i>=0){if($#i){$x=$i[1];} > else{$x='=';}$w{$i[0]}.=" ".$x;shift@i;}$n='>';while($n ne'='){print$n." "; > @l=split(' ',$w{$n});$n=$l[int(rand(1+$#l))];}print"\n";} > > Enter sentences without punctuation (e.g. "the cat sat on the mat"), > followed by return. It will print back sentences it makes up preceded by > ">". To see another sentence without bothering to type more input, just hit > return. Play with it for a while, see how stupid it is, and improve it. > > I expect to see a one-line version of this posted to the list within a week. > I'm starting to like this language. :) > Well, here's a start. I shortened it by 63 characters and squeezed it onto two lines. (-w not recommended ;) The terminator character is now '0' rather than '='. while(<>){split;$w{'>'}.=" $_[0]";while(@_){$w{$_[0]}.=$".($#_?$_[1]:0); shift@_}$n='>';while($n){print"$n ";split' ',$w{$n};$n=$_[rand@_]}print$/} Ronald ==== Want to unsubscribe from Fun With Perl? ==== Well, if you insist... Send mail with body "unsubscribe" to ==== fwp-request@technofile.org