Problems? Is your data what you think it is? PerlMonks

### Macaroni and Cheese

by Ovid (Cardinal)
 on Sep 04, 2000 at 22:37 UTC 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
}

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";
}
}

Create A New User
Domain Nodelet?
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?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (2)
As of 2024-03-02 05:47 GMT
Voting Booth?
My favourite way to spend a leap day ...

Results (29 votes). Check out past polls.