Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

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

by GrandFather (Saint)
on May 19, 2021 at 01:36 UTC ( #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?

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (3)
As of 2021-10-18 10:54 GMT
Find Nodes?
    Voting Booth?
    My first memorable Perl project was:

    Results (73 votes). Check out past polls.