Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Macaroni and Cheese

by Ovid (Cardinal)
on Sep 04, 2000 at 22:37 UTC ( #31023=poem: print w/ replies, xml ) Need Help??

One of the exercises that you often receive in beginning programming classes is to write a recipe in such detail that a computer would understand, if it could understand your native language. Of course, this isn't possible, so I decided to make the task a bit easier for the computer.
#!/usr/bin/perl -w use strict; use Carp; use vars qw($pleasure $I $lunch); my %ingredient = ( butter => '1/4 cups', milk => '1/4 cups', macaroni => '1 1/2 cups', water => '6 cups', salt => '1 pinch', cheese_like_substance => '1 pouch' ); open BOOK, "<" , "Cryptonomicon" or carp "Where's my friggin' book?! $ +!\n"; my @pot = ($ingredient{'water'}, $ingredient{'salt'}); for my $water_temperature (75..212) { read BOOK, $pleasure, 2048 or die "What else has Neal Stephenson w +ritten?"; } push @pot, $ingredient{'macaroni'}; STIR_MACARONI: { for my $minutes (7..10) { read BOOK, $pleasure, 2048 or die "I need another book!"; last STIR_MACARONI if ($ingredient{'macaroni'} eq 'glue'); } } splice @pot, $#pot/2, 0, $ingredient{'butter'}; my $pot = join '', @pot; $pot .= $ingredient{'milk'}; STIR_MACARONI_AGAIN: { my @lunch = split //, $pot; for (0..10) { splice @lunch, rand($#lunch), 0, $ingredient{'cheese_like_subs +tance'}; } $lunch = join '', @lunch; } if ($I eq eat($lunch)) { read BOOK, $pleasure, 2048 or carp "I hate mac and cheese. It's just something to do whi +le reading."; } sub eat { my $food = shift; if (BOOK) { for (0..length($food)) { $food = substr $food, 0, (length($food) - 1); } } else { print "$food must be good if you ain't reading!\n"; } }

Comment on Macaroni and Cheese
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: poem [id://31023]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (10)
As of 2014-12-21 08:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (104 votes), past polls