Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

40,053 Philosophical Errors

by Zaxo (Archbishop)
on Jun 11, 2004 at 09:18 UTC ( #363339=CUFP: print w/replies, xml ) Need Help??

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,

Replies are listed 'Best First'.
Re: 40,053 Philosophical Errors
by QM (Parson) on Jun 17, 2004 at 02:00 UTC
    $ENV{HOME} is undefined on my Win32 system, so that generates an "Unitialized..." warning, but otherwise, it's great fun.

    Quantum Mechanics: The dreams stuff is made of

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: CUFP [id://363339]
Approved by Corion
Front-paged by grinder
[choroba]: it depends. Give more details, please
[thepkd]: i used a series of {}'s but it dont work
[choroba]: You need square brackets for arrays
[GotToBTru]: you can certainly construct a single expression to access any part of the data structure, without using temp variables. but you might make it easier on yourself and any other poor soul who has to understand your code if you do
[thepkd]: to dereference i mean
LanX .oO( oh tempz, oh moretz)
[thepkd]: @GotToBTru Sure. But.
choroba waits

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (13)
As of 2016-12-06 13:27 GMT
Find Nodes?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:

    Results (104 votes). Check out past polls.