in reply to How to verify array fields and print ONE message at the end

The code structure you have is not designed for one print at the end. It's designed to step through a list of username/password pairs.

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:

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);
Of course, I'm wondering where $in{'oldname'} and @indata come from, or even if they factor into the code your seeking.

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):

elsif ($username eq $in{'oldname'}) { $found = 1; last; }
(and keep the if (not $found) block).

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

Replies are listed 'Best First'.
Re: Re: How to verify array fields and print ONE message at the end
by FemmeGretha (Initiate) on Oct 29, 2003 at 15:56 UTC
    Hi, Thank you for your advice. I tried both suggestions, and I would wipe out my password database every time. If you have time and interest to look over the complete code, I will post it/send it to you. Please let me know. I would be thankful for any help in saving my sanity. FG