Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Next from inner loop only works "most of the time"

by GrandFather (Saint)
on May 19, 2021 at 01:36 UTC ( [id://11132724]=note: print w/replies, xml ) Need Help??


in reply to Next from inner loop only works "most of the time"

I'd replace the whole inner loop with next if grep {$seen{$_} > $masterLetterFreq{$_}} keys %seen; giving:

use strict; use warnings; my @result = ('thew', 'trow', 'whew '); my %masterLetterFreq = ('w' => 1, 'h' => 1, 't' => 1, 'o' => 1, 'r' => 2, 'e' => 1); for my $word (@result) { my %seen; $seen{$_}++ for split //, lc $word; next if grep {$seen{$_} > $masterLetterFreq{$_}} keys %seen; print "$word\n"; next; }

which avoids the goto label nonsense and avoids silly flag twiddling. Note that this code often generates a warning, but I haven't seen it print 'whew '. There is something more going on in your real code that gets 'whew' printed, but we don't have that code or a sample we can run to reproduce that error.

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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11132724]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (None)
    As of 2024-04-19 00:04 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found