> -----Original Message----- > From: Jame Brooke [mailto:[EMAIL PROTECTED] > Sent: Monday, March 14, 2005 6:31 AM > To: beginners@perl.org > Subject: matching password problem > > [code snip] > > > Dear all, > > Can anybody help me look script above, I¡¦m > detected the script above has a bug I cannot solve. I assume > have create a file call password.dat. This file I save 3 > record like below: > [ data snip ] > > > > Actually I want this script to call the password.dat to > verify my user id and password keyin is match with my > password.dat. If everything is match the user allow to view > the html form like I write above. > > > > The main problem is the looping cannot stop, and the script > only check a single condition only. Mean if the user ID is > correct, the visitor not need key in the password also can > view my html page. I also detected my script sometime can > work same time cannot work. May I know how to solve this > problem? Any comment return will appreciate. Thanks >
If your data was formatting a bit differently you might have better luck. I did cheat but maybe someone else can suggest based on existing structure. To get the username/passwords though throwing everything into a hash works very nicely: # Always, always, always use warnings; use strict; my (%user_file, $username, $password); #Open Password file sand store information into memory. open(PASSWORD, "password.dat") or die "Can't open file!: ($!)"; # Always check for success on open while (<PASSWORD>) { ($username, $password) = split('\s'); # Separate out data $user_file{$username} = $password; # Loading hash } # Print! for (sort keys %user_file) { print "$_ => $user_file{$_}\n"; } __END__ [ data ] 0001 test 0002 halo 0003 Bye -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>