[Techtalk] On Perl

jennyw jennyw at dangerousideas.com
Sun Jul 28 10:37:07 EST 2002


On Sat, Jul 27, 2002 at 03:06:33PM -0400, coldfire wrote:
> among other things, yes :)  but i should admit, my "horrible" remark was
> too harsh.  if it works, and only iterates over 3 elements in the array,
> time is pretty negligable don't you think? :P  but yeah, i didn't like the
> if-elsif-else structure they used ... but of course, the tutorials are to
> learn the language and syntax, not algorithm design hehe ..

Sometimes readability is more important than performance.  Here's another 
version of the code that's probably slower but more concise:

!/usr/bin/perl
@words = qw (llama camel alpaca);
print "what is your name\n";
$name = <stdin>;
chomp $name;
if ($name eq "tan") {
  print "hey man\n";
} else {
  print "hi, $name\n";
  print "enter the password\n";
  while (true) {
    $guess = <stdin>;
    chomp $guess;
    if (grep (/^$guess$/, @words)) {
      last;
    }
    print "wrong. try again\n";
  }
}




More information about the Techtalk mailing list