The code isn't pretty, I was told that some of the loops could have been merged into a single loop (and minor things like that).
The first problem I need help with is finding out why the WILD card filter system is leaving broken HTML tags. The script finds the WILD chards in the word, and applys a little HTML to it. The results are something like
From the printout above, you can see some font tags getting crammed in there. Someone mentioned yesterday that the problem might be the script is filtering out the HTML, too. For example, if an "o" is a wild, the "o" in "font" is also being s///. If this is the problem, I'm not sure how to apply the filtering.adapis , adipsy , agasp , aed>lephs , alisp , aont color=red>lphos , a +t color=red>lpist , apepsy , aphis , apont color=red>ios , aped>ont c +olor=red>iose , apis , apish , apism , aped>odes , aped>oise , aposia + , appius , aed>ont color=red>ppose , apsis , aped>lor=red>ulse , apu +s , asaph , nt color=red>ashpan , ast color=red>
Anyone have advice on what to do to get the wild filtering to work?
Full code:
if (param()) { my $letters = param("letters"); my $action = param("select"); $results = param("results"); my $selectbox = param("selectbox"); print "Your letters were: <b>$letters</b><p>"; ########### # any non a-z is a wild char ########### $blanks++ while $letters =~ s/[^a-z]//; $lhash{$_}++ for split //, $letters; ########################### # Open dictionary and begin checking word combos ########################### # dictionary opens, we get and find our words # words are placed in @solutions ############################# # At this point, we have our word list ############################# foreach my $found (@solutions) { my @chars = split(//, $found); # break word into chars my $score = 0; my $which_letter = $letters; # copy of letters to remove letters + found. this will aid in finding the wild chars my @wilds; # wild chars used my $find = $found; # $found after we apply font changes to wild +chars ############## # Break the word into characters and check which chars are wilds ############## foreach my $char (@chars) { if ($which_letter =~ m/$char/) { $which_letter =~ s/$char//; } else { push(@wilds, $char); } } ############# # tear word apart and get point value ############# my $found_word = $found; my $charlen = length $found; foreach(@wilds) { $found_word =~ s/$_//; } # removing the wilds my @found_word_letters = split(//, $found_word); foreach my $pt (@found_word_letters) { $score += $points{$pt}; } ##################################################### # # # WILD FILTERING HERE # # ##################################################### foreach my $wild (@wilds) { $find =~ s/$wild/<font color=red>$wild<\/font>/; } ################## # Remove words that don't follow user's wishes ################## if ($action eq "starts") { if ($find =~ m/^$selectbox/) { push @{$scored{$score}}, $find; push @{$bylength{$charlen}}, $find; } } elsif ($action eq "ends") { if ($find =~ m/$selectbox$/) { push @{$scored{$score}}, $find; push @{$bylength{$charlen}}, $find; } } else { push @{$scored{$score}}, $find; push @{$bylength{$charlen}}, $find; } #push( @wild, $which_letter ) unless( $which_letter =~ tr/$char//d ); }
This second problem is really racking my brain.
ANY help at all with this mess would be much appreciated. I know this code is pretty scary.
In reply to Problems with s/// by sulfericacid
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |