#!/usr/bin/perl
&parse_form;
print"Content-type:text/html\n\n";
$filename = 'data.txt';
open(myfile,"$filename");
@getrec = <myfile>;
close(myfile);
$cntrec = @getrec;
unlink("$filename");
open(myfile,">$filename");
foreach $rec (@getrec) {
($id,$ps) = split(",",$rec);
if ($v{'id'} ne $id) {
print myfile $rec;
} else {
print myfile "$v{'id'},$v{'passwd'},\n";
$found=1;
}
}
close(myfile);
if ($found){print'Update ok';}else{print'Not found';}
sub parse_form {
@pairs = split(/&/, <STDIN>);
foreach $pair (@pairs) {
local($name, $value) = split(/=/, $pair);
$name =~ tr/+/ /;
$name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ s/,/,/g;
$v{$name} = $value;
}
}
จำนวน : 34 บรรทัด