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


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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.