[EMAIL PROTECTED] said:
> sub init_words { open(WORDLIST,"wordlist") || die "can't open
> wordlist";
> while($name =<WORDLIST> )
> {
> chomp($name);
> $word=<WORDLIST>;
> chomp($word);
> $words{$name}=$word;
> }
> close(WORDLIST);
> }
>
> It ask you for your name then your password. If it doesn't match it
> goes into a loop until it gets it right. The problem is when you enter
> the correct password for the correct name it goes into the loop
> endlessly. I can't figure out why. This problem arose when I created
> the init_words sub routine. before I used the array
Ok, the problem here is that you input is getting a full line for each
call
on WORDLIST; ie: in the first cycle through the loop, $name = "fred
-name",
and $word = "camel -pwl". Given the form of your wordlist file, you
need to
split the line. The following works (by test, not just theory):
sub init_words
{
my $name="";
my $word="";
my $line="";
open(WORDLIST,"<wordlist") || die "can't open wordlist";
while($line =<WORDLIST> )
{
chomp($line);
($name, $word) = split(" ", $line);
$words{$name}=$word;
}
close(WORDLIST);
}
The problem is easily diagnosed if you'll take a couple of minutes to
learn
the perl debugger, and use the "-d" flag on the first line. By the
way, that
first line is also a problem; it should be:
"#!/usr/bin/perl -w", not "# /usr/bin/perl -w". The "#!" pair is what
clues
the shell to run the command following on the code in the file.
Twould be a good habit to get into declaring your variables, too. For
any
larger piece of code you'll have to start making use of "strict", and
it'll
become mandatory then. For example, your hash, words, should have been
declared as "my %words=();" early on in the file.
best & hope it helps.
rickf
--
Rick Forrister <[EMAIL PROTECTED]>
Definition: Honest Politician: Once bought, stays bought."
--Robert Heinlein
_______________________________________________
Redhat-list mailing list
[EMAIL PROTECTED]
https://listman.redhat.com/mailman/listinfo/redhat-list