First and foremost, I don't see you using strict anywhere. When you're messing with this many variables, especially a username and password, it's safer if you use strict; in the beginning of your program. Please refer to strict or type perldoc strict in CMD.
If you went with the SDBM route, you could check for already used usernames by using an if statement. Something like this is what I've always used (assuming the user name is used as the hash key):
Using a database rather than writing to a file will make your life a lot easier. You won't have to use while (<>), checking to see if particular elements are already stored and retrieving data is a million times easier and faster.foreach (keys %personalDetails) # iterate over every key/value pair st +ored in database { if (exists $personalDetails{$testUsername}) # check to see if the us +ername exists using "exist" { print "Error: This screen name is already being used.\n"; exit; } }
Another thing I noticed is you're adding leading spaces when you print to the personalData file. Are you sure you didn't want to put spaces at the end of the line instead?
Could be shortened into one line, since it's always nicer being lazy, right? print TEXTWRITE "$firstname,";print TEXTWRITE " $firstname"; print TEXTWRITE ",";
One final thought. Since you're using CGI.pm, you can forget about printing HTML headers the old fashion way. Let CGI.pm do the work for you. print header, start_html('This is the title of my page!'); prints all your header information for you in one line.
I hope this helps.
In reply to Re: Perl to wite and search text file
by sulfericacid
in thread Perl to wite and search text file
by Ragna
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |