FurryGorilla
Technical User
Hi I'm having a slight problem with something that seems to be quite common but I still can't find a solution :-(
Basically I have a form which passes a user name to a script which in turn compares these against a text file:
[tt]user1ass1:
user2ass2:
user3ass3:[/tt]
OK so I can read in the data from the form but how can I compare this against a line in the text file and then remove this line if the user name matches against one in the text file?
The code I have is as follows (goBoating thank you ;-)):
[tt]#!/usr/bin/perl
print "Content-type: text/html\n\n";
use CGI;
$cgi = new CGI;
$pwd_file = "pwd.txt";
$new_pwd_file = "temp.txt";
$uname = $cgi->param('username');
$pword = $cgi->param('password');
open (USERS, $pwd_file);
while (<USERS>) {
$buffer .= $_;
}
close USERS;
print "$buffer.\n";
@lines = split(/\n/,$buffer);
$line = "$uname:$pword:";
print $line;
push @lines, $line;
print @lines;
open (PWD, ">>$new_pwd_file"
foreach $line (@lines) {
print PWD "$line\n";
}
close PWD;[/tt]
As you can see I'm adding the user name and password onto the line and then writing to a different file. I'd prefer to overwrite the original file or possibly delete and rename. I'm just learning so I'm not sure about the splice command which seems to be popping up
Thanks in advance
Chris
Basically I have a form which passes a user name to a script which in turn compares these against a text file:
[tt]user1ass1:
user2ass2:
user3ass3:[/tt]
OK so I can read in the data from the form but how can I compare this against a line in the text file and then remove this line if the user name matches against one in the text file?
The code I have is as follows (goBoating thank you ;-)):
[tt]#!/usr/bin/perl
print "Content-type: text/html\n\n";
use CGI;
$cgi = new CGI;
$pwd_file = "pwd.txt";
$new_pwd_file = "temp.txt";
$uname = $cgi->param('username');
$pword = $cgi->param('password');
open (USERS, $pwd_file);
while (<USERS>) {
$buffer .= $_;
}
close USERS;
print "$buffer.\n";
@lines = split(/\n/,$buffer);
$line = "$uname:$pword:";
print $line;
push @lines, $line;
print @lines;
open (PWD, ">>$new_pwd_file"
foreach $line (@lines) {
print PWD "$line\n";
}
close PWD;[/tt]
As you can see I'm adding the user name and password onto the line and then writing to a different file. I'd prefer to overwrite the original file or possibly delete and rename. I'm just learning so I'm not sure about the splice command which seems to be popping up
Thanks in advance
Chris