http://qs321.pair.com?node_id=11132773


in reply to Re^2: Next from inner loop only works "most of the time"
in thread Next from inner loop only works "most of the time"

I crunched your code down a little to turn it into a test script. You may like to try running it to see if it reproduces the issue. If it doesn't you could try adding back elements of your script until you get back to a UFO. At that point you will have identified a critical component (whatever you added last) and that may help us figure out where the issue is.

use strict; use warnings; print "Starting\n"; for (1 .. 100000) { my @results = draw(); print "@results\n" if 2 != @results; } print "Done\n"; sub draw { my @dic = ('thew', 'trow', 'whew'); my %master_letter_freq; my $master_letter_list = 'otrwreh'; my $regex = ''; ++$master_letter_freq{$_} for split //, $master_letter_list; for (split //, '---w') { $regex .= $_ eq '-' ? "[$master_letter_list]" : $_; } my @result = grep {/^$regex$/i} @dic; my @results; RESULT: foreach (@result) { my %seen; $seen{$_}++ for (split //, lc $_); foreach (keys %seen) { next RESULT if ($seen{$_} > $master_letter_freq{$_}); } push @results, $_; } return @results; }

On my machine running Perl 3.30.1 prints:

Starting Done
Optimising for fewest key strokes only makes sense transmitting to Pluto or beyond