Some questions to answer, topics to consider:
Please give examples.
The simple vending machine was presented in week two notes:
#!/usr/bin/perl
%contents = ("snickers" => 70, "pretzels" => 50, "soda" => 75);
print "Welcome to the vending machine!\nready> ";
while ($input = <STDIN>) {
chop($input);
if ($input eq "quit") { last; }
elsif ($input =~ /^add\s/) {
($add, $what, $price) = split(/ /, $input, 3);
$contents{$what} = $price;
} elsif ($input =~ /^\s*show\s+all\s*$/i) {
foreach $key (keys %contents) {
$price = sprintf("%4.2f", $contents{$key} / 100);
print $key, " --> \$", $price, "\n";
}
} elsif ($contents{$input}) {
$price = sprintf("%4.2f", $contents{$input} / 100);
print $input, " costs \$$price\n";
} else {
print "I don't understand $input, sorry.\n";
print "Try: show all, add <product> <cents>, <product>, or quit\n";
}
print "ready> ";
}