in reply to Variable still not holding contents
Well, that ain't a loop at all. "unless" is not a looping control word. You probably want "while" or "until". In pseudocode, you probably mean until ( $_ not in @stored ) or the equivalent, while ( $_ in @stored ) Now, as for how you're checking whether $_ is in @stored, a simple "eq" or "ne" is not going to get it. You can use the grep function, which, in scalar context, returns the number of "matches". Like so: $n_found = grep { $pw eq $_ } @stored; In the condition of a while loop, it would look like this: while ( grep { $pw eq $_ } @stored ) The other mistake you made was to test $_ in the condition, rather than $pw; but that was probably a simple typo. However, we're not out of the woods yet, because, as it stands, the while condition will always test false on the first iteration, for the simple reason that $pw has no value yet, and thus will never be found in the list. (Unless, of course, and undef somehow got into the list...) One way to account for that is to give $pw its first value before entering the loop test for the first time:# attempt at looping unless ($_ ne @stored) { $pw = join(@chars[map{rand @chars} (1..17)]; }
But that's ugly. An alternative is to switch the loop style to use the test-at-end form of while, aka "do-while":$pw = join(@chars[map{rand @chars} (1..17)]; while ( grep { $pw eq $_ } @stored ) { $pw = join(@chars[map{rand @chars} (1..17)]; }
do { $pw = join(@chars[map{rand @chars} (1..17)]; } while ( grep { $pw eq $_ } @stored );
jdporter
The 6th Rule of Perl Club is -- There is no Rule #6.
|
|---|