Tell us how you plan to use the code you've shown with the feature you're seeking, and we might give a better answer.
In the meantime, I'm guessing you want something like this:
Of course, I'm wondering where $in{'oldname'} and @indata come from, or even if they factor into the code your seeking.open(TEMP,">$tmpfile") || die "Can't create $tmpfile.\n"; $found_user = 0; # flag foreach $i (@indata) { chomp($i); ($username,$password) = split(/\|/,$i); if ($username eq $in{'oldname'}) { $found = 1; last; } } if (not $found) { print TEMP "Username $username is not registered\n"; } close(TEMP);
OTOH, if you're looking to incorprate this behavior in your given code example, change the else to something like this (or perhaps insert this in front of it):
(and keep the if (not $found) block).elsif ($username eq $in{'oldname'}) { $found = 1; last; }
You should probably add a last; to each of the if/elsif blocks, unless you're planning on doing something with every username in @indata.
-QM
--
Quantum Mechanics: The dreams stuff is made of
In reply to Re: How to verify array fields and print ONE message at the end
by QM
in thread How to verify array fields and print ONE message at the end
by FemmeGretha
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |