Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I came across an article by Sharon Hopkins,'Camels and Needles', subject Perl Poetry. Is there anyone out there who can tell me where I can get hold of some simple perl poetry code that produces a poem as output. I'd be grateful for anything. Thanks :)

20031204 Edit by jeffa: Changed title from 'perl poetry'

  • Comment on Seeking Perl poetry code that writes poems

Replies are listed 'Best First'.
Re: Seeking Perl poetry code that writes poems
by idsfa (Vicar) on Dec 03, 2003 at 19:07 UTC

    I've always liked TheDamian's Coy, which was covered in ThePerlJournal. It turns your error messages into haiku.

    Of special note in that article was:

    # Life ends with a crash require 'Coy.pm'; &laughter while $I, die;

    Credited to Michael Schwern.


    I'm going to the AngryDome now.
Re: Seeking Perl poetry code that writes poems
by Paladin (Vicar) on Dec 03, 2003 at 16:53 UTC
    Have you checked out the Perl Poetry section, right here on PerlMonks? There are quite a few snippets of Perl poetry in there.

      I think the OP is asking for programs or code snippets that write poetry, rather than actual poetry samples. In that case, it may be worth looking in Cool Uses For Perl or Snippets. (I'm not sure there's anything in there, but then again, I'm not sure exactly what the questioner wants. ;-)

Re: Seeking Perl poetry code that writes poems
by Roger (Parson) on Dec 03, 2003 at 19:00 UTC
    There is a Poetry BOT (written in Perl?) for sale here. But you will have to pay for it.

    merlyn has an article on random sentence generator on his stonehendge site here. It generates interesting random sentences. Not peoms, but it is a good starting point.

    I am thinking of writing a simple poetry bot for fun, just a proof of concept.

      This is the same site which sells a perl de-obfuscator script for 25 USD, which as far as I can see does nothing else but inserting linefeeds after each ';', so I'd be careful about the poetry bot!

      CountZero

      "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law

Re: Seeking Perl poetry code that writes poems
by opqdonut (Acolyte) on Dec 03, 2003 at 17:58 UTC

    It's so nice that now evrybdy gets the Duplicates found error message when clicking on the Perl Poetry link... Could somebody a bit rootish change the name of this question node to "crappy name choice" for example ;)


    eternally irritated,
    J

    <obfu type="witty">er...</obfu>
Re: Seeking Perl poetry code that writes poems
by CountZero (Bishop) on Dec 03, 2003 at 20:16 UTC
    Have a look here (ppgen). It is a perl-script which generates poetry, but not perl poetry.

    Perl poetry is of course a perl script which compiles without errors but at the same time evokes a concentrated imaginative awareness of experience or a specific emotional response through language chosen and arranged for its meaning, sound and rhythm (Encyclopedia Britannica definition of "poetry").

    CountZero

    "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law

Re: Seeking Perl poetry code that writes poems
by Roger (Parson) on Dec 03, 2003 at 23:28 UTC
    Ok, I have implemented a little random text/poem/haiku generator. I bumped into Julie Zelenski's webpage when I was searching for some perl poetry material. I had a look at the grammar, thought it was fun, and easy to parse. So I implemented a perl version of the grammar parser and random text/poem generator. It was pretty fun to play with, especially with a Star Trek episode generator (yeah you can tell I am a big star trek fan ;-)). Here it goes...

    #!/usr/local/bin/perl -w use strict; use Data::Dumper; =pod # # ok, the following is the location of the grammar files at # Julie Zelenski's webpage at stanford's computer science faculty. # I was thinking about using WWW::Mechanize or LWP::Agent to # fetch the grammar files, but couldn't be bothered. # my $rsg_grammar_url = "http://www-cs-faculty.stanford.edu/~zelenski/rsg/grammars/"; =cut # load the grammar definition file my $grammar = do { local $/; <DATA> }; my %grammar = %{parse_grammar($grammar)}; # print Dumper(\%grammar); my $text = random_text_from_grammar("start"); $text =~ s/(.{50,60}(?<=\s\b))/$1\n/mg; print "$text\n"; # parse the simple grammar and build a hash table sub parse_grammar { my $grammar = shift; my %grammar = $grammar =~ /^{\s*<([^>]+)>\s*([^}]+)}/mg; foreach (keys %grammar) { $grammar{$_} = [ map { s/[^\S\n]+/ /g; s/\s([.?,;!])/$1/g; $_ } split /\s*;\s*/, $grammar{$_} ]; } return \%grammar; } # generate the text recursively sub random_text_from_grammar { my $token = shift; my $selection = $grammar{$token}; my $phrase = $selection->[rand ($#$selection+1)]; $phrase =~ s/<([^>]+)>/random_text_from_grammar($1)/ge; return $phrase; } __DATA__
    When I ran it, I got some pretty interesting text -
    Kyoto smile Nick through / day Kyoto drifting subway / temple my ocean - Hokusai rising computer / dusk Mitsukoshi day Nick / hell samurai tree - Toshiba wave white Tokyo wave / toward mountains higher empty / computer faces - Hokusai Mitsukoshi pool / sushi wave dusk Parlante / white subway sound birds - Toshiba Buddhist cranes cranes fly / Kyushu sun rice fields sea through / temple white thinking - Basho
      Ok, this is a tribute to the wonderful perlmonks site - a grammar I am working on that describes an event that could/might/had happened at perlmonks. I thought it was quite fun to play with, so I am posting it here. Please feel free to add to the grammar or give suggestions. ;-)

      The perlmonks grammar:


      And when I ran the text generator in the previous post, I got some quite funny results -
      Thursday this week, some monk encountered an idea on how to do networking and wish to inform other monks at Perlmonks. bad luck no monks gave any response. he was up voted. once upon a time, intermediate monk bumped into a need some pointers using Expect.pm problem. bad luck no monks gave any response. he was down voted because it was too simple. Monday last week, bishop monk encountered a problem on need some pointers using Expect.pm. it stired some responses from monks. she was up voted because it gave a good challenge. ...
      Have fun. ;-)