#!/usr/bin/perl -l

#                                                          ppg256-1.pl
# Perl Poetry Generator in 256 Characters, Number 1
# Nick Montfort nickm@nickm.com
#====================================================================#
#
# This is a reformatted and commented version of a Perl program that 
# will run on Mac and Linux on the command line and which is 256 
# characters long:
#
# perl -le 'sub b{@_=unpack"(A2)*",pop;$_[rand@_]}sub w{" ".b("cococacamamadebapabohamolaburatamihopodito").b("estsnslldsckregspsstedbsnelengkemsattewsntarshnknd")}{$_="\n\nthe".w."\n";$_=w." ".b("attoonnoof").w if$l;s/[au][ae]/a/;print;$l=0if$l++>rand 9;sleep 1;redo}'
#
# The only changes that have been made are the addition of spaces,
# newlines, and a few comments.
#
# On Windows, install ActivePerl to be able to run this program.
# To run, change to the directory where this file is located and type
# at the command prompt:
#
# perl -l ppg256-1.pl

sub b # Select a bigram (two letters) at random from a long string
  {
    @_=unpack"(A2)*",pop;
    $_[rand@_]
  }

sub w # Return a space followed by a four-letter word
  {
    " ".b("cococacamamadebapabohamolaburatamihopodito").
    b("estsnslldsckregspsstedbsnelengkemsattewsntarshnknd")
  }

{ # Main loop
  $_ = "\n\nthe".w."\n";
  $_ = w." ".b("attoonnoof").w if $l;
  s/[au][ae]/a/;
  print;
  $l = 0 if $l++ > rand 9;
  sleep 1;
  redo
}

