In the first attempt, try to set the if inside the loop:
foreach my $pair(@incomingarray) {
(my $name,my $value) = split (/:/, $pair);
if ($name eq $username) {
print p("Username is already taken, try again");
close(YYY);
print end_html();
}
else {
open(YYY, ">>password.txt");
print YYY $username.":".$hashpass."\n";
print p("Your account has been created sucessfully");
close(YYY);
print end_html();
}
}
In your second attempt, I think you should try and change the line:
if (%users eq $username) {
with this:
if (defined $users{$username}) {
source
share