This is a novelty application which generates a random synthetic haiku from your system error messages and writes it to STDERR. The result is similar to the handmade one at Obfu Errno Haiku.

The script stands at version 0.9 while I straighten out Pod::Usage usage. The 40053 figure is the number of possible results on Linux and doesn't count decorative differences in punctuation. I believe this will run on any platform and give relatively meaningful results - such as they are.

#!/usr/bin/perl use strict; use warnings; use Pod::Usage; =head1 NAME haiku - send a system warning haiku over STDERR =head1 SYNOPSIS haiku [--cache] [--help] [--verbose] [--version] =cut use vars qw/ %syllables $threes $fours $fives $sevens $seven_lines $haiku $verbose $cache $VERSION /; BEGIN{ $VERSION=0.9; } =head1 OPTIONS =over 8 =item B<-c, --cache> Cache the system message store to ~/.haikurc =item B<-h --help> Print a usage message. =item B<-verb, --verbose> Be verbose, =item B<-V, --Version> Print haiku information and exit. =item B<-vers --version> Print haiku version and exit. =back =cut use Getopt::Long; BEGIN { GetOptions( 'verbose!' => \$verbose, 'cache!' => \$cache, 'version' => sub { print $VERSION, $/ and exit(0)}, 'Version' => sub { print "system error haiku, v$VERSION, by Z +axo of Perlmonks$/" and exit(0)}, 'help' => sub { pod2usage(1) }, ) or pod2usage(1); } use Lingua::EN::Syllable; sub syllables { my $count = 0; $count += syllable($_) for @_; $count ? $count : (); } { my @punc = ( ' - ', (', ') x 3, ': ', '; ', ('. ') x 2, (' ') x 3 ); sub punct { $punc[rand @punc] } } { my @terminal = ( ('.') x 5, '!', '?', ); sub terminal { $terminal[rand @terminal] } } if (-f "$ENV{HOME}/.haikurc" and !$cache) { %syllables = %{ do "$ENV{HOME}/.haikurc" }; } else { my @messages = grep { $_ and ($!=$_) !~ /\d/ } 0 .. 255; for (@messages) { push @{$syllables{syllables(split ' ', $!=$_)}}, $_; } } if ($cache) { use Data::Dumper; open my $fh, '>', "$ENV{HOME}/.haikurc" or die $!; print $fh Dumper(\%syllables); close $fh or die $!; } $fives = scalar @{$syllables{5}}; $sevens = scalar @{$syllables{7}}; $fours = scalar @{$syllables{4}}; $threes = scalar @{$syllables{3}}; $seven_lines = $sevens + 2*$fours*$threes; $haiku = $fives * $fives * $seven_lines; exit main(); =head1 DESCRIPTION B<haiku> constructs a random 5-7-5 syllable message out of the system +error messages. The message is printed over STDERR. B<Lingua::EN::Syl +lable> is required to count syllables. =cut sub pick { my $sybs = shift; $! = $syllables{$sybs}[rand @{$syllables{$sybs}}]; "$!" } sub pick_first { pick(5) . punct } sub pick_second { my $selector = rand $seven_lines; $selector < $sevens && return pick(7) . punct; $selector < $sevens + $fours * $threes && return pick(4) . punct . pick(3) . punct; pick(3) . punct . pick(4) . punct; } sub pick_third { pick(5) . terminal } sub main { return -1 unless $haiku; print "One of $haiku haiku, brought to you by *STDERR\n" if $verbo +se; warn pick_first, $/; warn pick_second, $/; warn pick_third, $/; 0; } __END__ =head1 SEE ALSO L<Lingua::EN::Syllable>, L<Getopt::Long>, L<Pod::Usage>, L<Data::Dumpe +r> =head1 FILES L<${HOME}/.haikurc> =head1 AUTHOR Zaxo of Perlmonks =head1 COPYRIGHT 2004, by Zaxo =head1 LICENSE Same as Perl =cut

After Compline,
Zaxo


In reply to 40,053 Philosophical Errors by Zaxo

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.