On Wed, 1 Nov 2000, Larry Mintz wrote:
> It can't this stupid program to terminate properly.
<snip>
> 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);
> }
>
>
> The WORDLIST file is
> fred -name
> camel -pwl
> barney -name
> llama -pw
> linus
> tux
>
>
> 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
>
> %words = qw(fred camel
> barney llama
> linus tux
> );
> it worked fine. Now things are fubared. Why ?
perl is line oriented by default. So when processing the worlist file you
are picking up the entire odd numbered lines as names, and the even
numbered lines as passwords. Try something like this
while( <WORDLIST> )
{
chomp();
my ( $name, $word ) = /([^\s]+)\s*(.*)$/;
$words{$name}=$word;
}
Since I don't know exactly what format you want to allow, this simple
regular expression doesn't allow for leadign whitespace, commented lines
etc. But I hope you get the idea.
hth
charles
_______________________________________________
Redhat-list mailing list
[EMAIL PROTECTED]
https://listman.redhat.com/mailman/listinfo/redhat-list