With the same problems I had yesterday, I decided to post a little more of the source code to give you a better idea of what everything looks like.

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

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>
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.

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 ); }
The second problem is that when wilds are found, it will only add font changes to the FIRST instance of the wild in the word. Meaning, if the same word has two wild characters that are the same (two wilds being S's, for example), only the first is affected. If they are different letters, then it works fine.

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.



"Age is nothing more than an inaccurate number bestowed upon us at birth as just another means for others to judge and classify us"

sulfericacid

In reply to Problems with s/// by sulfericacid

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.