If you want to loop, you need to use a loop construct, not a conditional statement (and especially not a double-negative conditional :) I take it you want to search @stored for a submitted password, (is it really stored in $_?), and if you fail to find it then you generate a new one. Try:

my $submitted_pw = $_; my $pw; foreach my $stored_pw (@stored) { if ($submitted_pw eq $stored_pw) { $pw = $stored_pw and last; #exit the loop if we found a match } } # If $pw wasn't set in the loop, create a new password $pw ||= join(@chars[map{rand @chars} (1..17)];

Another way:

my $submitted_pw = $_; my $pw = grep($submitted_pw eq $_, @stored) ? $submitted_pw : join(@ch +ars[map{rand @chars} (1..17)];

Update: well there I go answering the wrong question again. How about this:

my %lookup_pwds; $lookup_pwds{$_}++ for (@stored}; do { $pw = join(@chars[map{rand @chars} (1..17)]; } while ($lookup_pwds{$pw});

In reply to Re: Variable still not holding contents by djantzen
in thread Variable still not holding contents by sulfericacid

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.