Folks, where better to ask than in a forum for developers, many of you
Perl wizards. :)

I have asked this in my local LUG, but I have not received an
explanation as to the why's.

Okay, here I sit going through my new, although outdated, book "Learning
Perl", and I am diligently typing in all the examples to ensure I truly
complete the book as intended. I have already run into a problem with my
sixth example in chapter 1.

Here is the code:

#!/usr/bin/perl -w
%words = qw (
    fred      camel
    barney    llama
    betty     alpaca
    wilma     alpaca
);
print "What is your name? ";
$name = <STDIN>;
chomp ($name);
if ($name =~ /^randal\b/i) {
    print "Hello, Randal! How good of you to be here!\n";
} else {
    print "Hello, $name!\n";     # ordinary greeting
    $secretword = $words{$name}; # get the secret word
    if ($secretword eq "") {     # oops, not found
        $secretword = "groucho"; # sure, why a duck?
    }
    print "What is the secret word? ";
    $guess = <STDIN>;
    chomp ($guess);
    while ($guess ne $secretword) {
        print "Wrong, try again. What is the secret word? ";
        $guess = <STDIN>;
        chomp ($guess);
    }
}

The example does not show the use of the -w switch, but it is used in
previous examples. If I take out the -w switch it does not show me the
error, but it still behaves the same.

When I run the script, if I enter the name 'fred' in lowercase letters
it works fine, but if I enter the name in uppercase, I get the following
error:

"Use of uninitialized value in string eq at ./hello_world_6.pl line 16
<STDIN> line 1."

I then have to use the "groucho" secret word to end the script.  Is this
something that has changed with since Perl 5.004, which was current when
the book was written? I am running Perl 5.6.0. on SME 5.1.2 (Update-1
applied)

I tried finding the examples at the O'Reilly ftp site as mentioned in
the book to verify my typing, but they have changed their site since
1997.

Thanks!

Tom Carroll
Dataware Computers


--
Please report bugs to [EMAIL PROTECTED]
Please mail [EMAIL PROTECTED] (only) to discuss security issues
Support for registered customers and partners to [EMAIL PROTECTED]
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
Archives by mail and http://www.mail-archive.com/devinfo%40lists.e-smith.org

Reply via email to