in reply to elsif failing

The problem is that you are using the assignment operator '=' rather than an equality operator ('==' or 'eq'). Assignment returns whatever was assigned and 'larry' (the first string assigned) is a true value so the first if test always succeeds.

If you find yourself writing the same code over and over again you should think about how you can rewrite it to avoid repeating yourself. In this case a look up table (hash for the initiated) is the answer. Consider:

use strict; use warnings; my %names = (larry => 'Larry', moe => 'Moe', curly => 'Curly'); print "What is your name?\n"; chomp(my $name = <STDIN>); if (exists $names{lc $name}) { print "You\'re $names{lc $name}!\n" } else { $name = ucfirst $name; print "I don't know anyone by the name $name\n"; }

Note that the hash keys are entered lower case but the hash values have the correct case and that the hash look up uses the lower case version of the given $name string. This lets names with characters of any case to match, but prints out the correct case.

The other thing to note is how easy it is to add another bunch of names. You could even read them in from a file with just a little effort.


True laziness is hard work