Of course, before posting, I thought I'd check if someone else already did this here, and sure enough, wombat did. (Edit: And andreychek also. Nice use of fork!)
My approach is different from theirs, though, so I figured I'd post this anyways.
Note that Jabberwocky.pm is left as an exercise to the reader :)#!/usr/bin/perl -w use strict; #Jabberwocky use Jabberwocky qw( $brillig @toves @borogroves @mome $son $vorpalSword $manxome $tumtumTree $Jabberwock $tulgeyWood $parent ); use Thread; =pod Author Lewis Carroll, translated to Perl by RMGir =cut =poem 'Twas brillig, and the slithy toves Did gyre and gimble in the wabe: =cut if($brillig->twas()) { foreach(@toves) { $_->gyre($wabe); $_->gimble($wabe); } } =poem All mimsy were the borogoves, And the mome raths outgrabe. =cut foreach(@borogroves) { die unless $_->mimsy(); } foreach(@mome) { $_->outgrabe(); } =poem "Beware the Jabberwock, my son! The jaws that bite, the claws that catch! Beware the Jubjub bird, and shun The frumious Bandersnatch!" =cut $parent->warn(<<WARNING); "Beware the Jabberwock, my son! The jaws that bite, the claws that catch! Beware the Jubjub bird, and shun The frumious Bandersnatch!" WARNING =poem He took his vorpal sword in hand: Long time the manxome foe he sought--- So rested he by the Tumtum tree, And stood awhile in thought. =cut $son->wield($vorpalSword); while(!$son->see($tumtumTree)) { $son->seek($manxome->foe()); } =poem And as in uffish thought he stood, The Jabberwock, with eyes of flame, Came whiffling through the tulgey wood, And burbled as it came! =cut sub bandersnatchWhiffle { $Jabberwock->has(EYES_OF_FLAME) or die; $Jabberwock->moveTo($tulgeyWood) do { $Jabberwock->whiffle(); $Jabberwock->burble(); } until($Jabberwock->see($son); } my $banderThread=new Thread \bandersnatchWhiffle; while($son->uffish() && !$son->see($Jabberwock)) { $son->think(); } $banderThread->join(); =poem One, two! One, two! And through and through The vorpal blade went snicker-snack! He left it dead, and with its head He went galumphing back. =cut for(1,2,1,2) { $son->sword()->slice($Jabberwock); $son->sword()->snickerSnack(); } die unless $Jabberwock->isDead(); $son->pickUp($Jabberwock->head()); $son->galumph($son->home()); =poem "And hast thou slain the Jabberwock? Come to my arms, my beamish boy! O frabjous day! Callooh! Callay!" He chortled in his joy. =cut $parent->chortle(<<FRABJOUS); And hast thou slain the Jabberwock? Come to my arms, my beamish boy! O frabjous day! Callooh! Callay! FRABJOUS =poem 'Twas brillig, and the slithy toves Did gyre and gimble in the wabe: All mimsy were the borogoves, And the mome raths outgrabe. =cut if(brillig->twas()) { foreach(@toves) { $_->gyre($wabe); $_->gimble($wabe); } } foreach(@borogroves) { die unless $_->mimsy(); } foreach(@mome) { $_->outgrabe(); }
|
|---|