thran has asked for the wisdom of the Perl Monks concerning the following question:
Ignore the last code, since I first have to figure out this line to fix the others :) I need the user to type down a username, and put it in the variable $login. Then the script does some checking on it. Doesnt seem to work though.. :( This is the entire script as it is now :print $client "username:"; $login=<$client>; print $login;
#!/bin/perl use IO::Socket; use IO::Select; $nconnections_new = 0; $login = ""; $maxconn = SOMAXONN; $local=IO::Socket::INET->new(Proto=>"tcp", LocalPort=>"1234", Listen=> +$maxconn, Reuse=>1) or die "Can't open socket\n"; while ($client = $local->accept) { $client->autoflush(1); &start; sub start { print $client "This is a test BBS!\n\r"; print $client "(C)reate new user (L)ogin"; print $client "\n\r"; $msg = ""; while ( <$client>) { next unless /\S/; if (/c|C/i) { print $client "<<<Create new user>>>\n\r"; print $client "Login must be at least 6 characters.\n\r"; &login; } elsif (/l|L/i) { &logon; } } sub login { print $client "username:"; $login=<$client>; print $login; chop $login; if ($login eq "") { print $client "Must enter a username!\n\r"; &login; } open (FILE1, "users.txt") || print "Error occured while opening file"; while (<FILE1>) { ($first, $second ) = split /:/; if ($login eq $first) { do { print $client "Sorry this username has been taken, try again!\n\r"; &login; } while ($login eq $first); } } if (length($login) > 6) { print $client "Your username was longer than 6 characters!\n\r"; &login; } close (FILE1); $pass = password(); sub password { print $client "Password:"; $password=<STDIN>; chop $password; print $client "\n\rRe-enter password:"; $password2=<STDIN>; chop $password2; if ($password ne $password2) { print $client "Passwords do not match, try again!"; &password; } return $password; } open (FILE, ">>users.txt") || print "Error occured while opening file" +; print FILE "$login:$pass\n"; close (FILE); print "File written..\n\r"; exit; } } sub logon { print $client "test"; } close $client; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Cant get user input from sockets into variables.
by wog (Curate) on Sep 22, 2001 at 17:18 UTC | |
|
Re: Cant get user input from sockets into variables.
by alien_life_form (Pilgrim) on Sep 22, 2001 at 18:17 UTC | |
by wog (Curate) on Sep 22, 2001 at 19:03 UTC |