Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

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

by Marshall (Canon)
on May 20, 2021 at 11:16 UTC ( [id://11132772]=note: print w/replies, xml ) Need Help??


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

I appreciate your suggestion!

This very well could be the "solution to the problem".
And also explain why previous commands made a difference in the result.
A state dependent failure where what happened before affects what happens now.

My previous thinking of reproducing an entire session would have caused a "hard failure".
The issue is "previous state" dependent.

Thank you, Marshall

if ($line =~ /^\s*:([a-zA-Z]+)\s*$/) # new list of letters { $master_letter_list = lc $1; ## Force all letter lists to LOWE +R CASE only %master_letter_freq=(); ########### ADDED ########## for (split //,$master_letter_list) { $master_letter_freq{$_}++; } print "master_letter_freq:\n"; print Dumper \%master_letter_freq; ##################### }
Here is a new version of wm.pl:
use strict; use warnings; use Data::Dumper; # Word Master -- quick hack on 5/18/2021 # en-US.dic is a flat file of sorted words (about 150K words) open (my $fh, '<', 'en-US.dic') or die "can't find dictionary file: en +-US.dic"; my @dic = map{chomp; $_}grep {!/'/ and !/[A-Z]/}<$fh>; #no apostrophes + allowed #no proper nouns Rome (capit +al letters) $0 =~ m!([\w. ]+)\s*$!; print "Word Master ($1)\n"; #like wm.pl this allows renaming the pro +gram print "# Enter list of letters by using colon or semicolon followed by + the letters\n"; print "# example>:omdee\n"; print "# in pattern, use simple dash for single unknown letters\n"; print "# m-de would match \"mode\"\n"; print "# quit|exit|q to exit program\n"; print "\n"; my $line; my %master_letter_freq; my $master_letter_list =""; #could be repeated letters like ee,tt,etc while ( (print "list of letters or pattern: "),$line=<>, $line !~ /\s* +quit|exit|q\s*$/i) { next unless $line =~ /\S/; #skip blank lines chomp $line; my $cur_pattern; if ($line =~ /^\s*[:;]([a-zA-Z]+)\s*$/) # new list of letters { $master_letter_list = lc $1; ## Force all letter lists to LOWE +R CASE only %master_letter_freq = (); for (split //,$master_letter_list) { $master_letter_freq{$_}++; } #print "master_letter_freq:\n"; #print Dumper \%master_letter_freq; ##################### } elsif ($line =~ /^\s*([a-zA-Z-]+)\s*$/) #no leading ":" or ";", this + is a pattern { $cur_pattern = lc $1; # Force all patters to LOWER CASE only if ($master_letter_list eq "") { print "No master letter list exists -> can't run this patt +ern! Error!\n"; next; } my $regex = ''; for (split //, $cur_pattern) # gen regex { if ($_ ne '-' and !exists $master_letter_freq{$_}) { print "Pattern has a letter that's not in master list! + Error!\n"; next; } if ($_ eq '-') {$regex .= "[$master_letter_list]";} else {$regex .= "$_";} } my @result = grep{/^$regex$/i}@dic; # filter out any result that is proper noun or if the number o +f # times a letter is repeated is more than the number of times +it is # repeated in the master letter list # foreach (@result) { my %seen; $seen{$_}++ for (split //,lc $_); # print "Testing Result $_, seen histogram is:\n"; # print Dumper \%seen; my $no_print = 0; foreach (keys %seen) { $no_print++ if ($seen{$_} > $master_letter_freq{$_}); } print "$_\n" unless $no_print;; } } else { print "Illegal input line!\n"; } } __END__ C:\Users\xxxx\Documents\Dictionary\en-US\en-US>perl wm.pl Word Master (wm.pl) # Enter list of letters by using colon or semicolon followed by the le +tters # example>:omdee # in pattern, use simple dash for single unknown letters # m-de would match "mode" # quit|exit|q to exit program list of letters or pattern: ;otrwreh list of letters or pattern: --r-w threw throw list of letters or pattern: ---w thew trow list of letters or pattern: q C:\Users\xxxx\Documents\Dictionary\en-US\en-US>

Update:
I am using the improved code and so far no program issues have been found.
The words in these puzzles are just crazy!
list of letters or pattern: :lfseka
list of letters or pattern: --e
ale

The correct word was FAE!

"The most commonly accepted meaning of the word “fae” on the internet is that the word is a shortened abbreviation for the word “fairy.” “Fairy” in this sense meaning the mythical and playful, often mischievous, human-like woodland creatures from stories and legends."
Perl cannot help with wacko stuff like that!

Update:
I just started a new puzzle with :buepol
My very first guess was "bole" and it worked.
GEEZ!
my second guess was "plebe" - that didn't even count as a valid word! What ?!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2024-04-19 14:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found