What's $COOKIES? Variable names are case sensitive, so it's not the same as $cookies. Use strict and warnings to be safe.
To increment a variable by 1, use just $var++, no assignment there.
exit is not needed at the very end of the script. What else could perl do at the end of the source code?
If you compare how the string in the condition is built with the string that's printed, you'll notice small differences. It's better to only have one place to create the string - a subroutine. Avoid copy and paste, it's hard to maintain. Maybe like this:
#!/usr/bin/perl use warnings; use strict; sub cookies { my $number = shift; return ('COOKIES ' x ($number - 1) . 'COOKIES' . 'S' x $number) } my $number = 1; my $cookies = ""; while ($cookies ne cookies($number)) { $number++; print 'Cookie monster: I want ', cookies($number), "!\n"; chomp($cookies = <STDIN>); } print "Mmmm. $number COOKIES. :-)\n";
In reply to Re: Loop and Add more cookies
by choroba
in thread Loop and Add more cookies
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |