Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Thank you so much...

You're so welcome! I'm glad to see someone having fun with this. Do you happen to have a source of cryptograms in electronic form, such that you can extract input files for use with your version of the script? Or are you just using a text editor to create your input files? (I would have used my version more often if I didn't have to always type in the puzzle from the newspaper or puzzle book.)

If you're going to insist on having a puzzle file provided as a command-line arg, you can leave out the "Read File" button -- just call your "readFile" sub before you call MainLoop.

As for loading (a big or huge version of) a "dictionary" file that has been crafted in some strange and mysterious way, that seems like too much work -- there must be a way to just use a simple word list. I would point out that your format doesn't really need the initial "string length" field, since this is evident from the string itself.

I don't really understand what's going on with the patterns and the dictionary, but alas, I feel like you ought to be scolded about this part of your "doword" sub:

... my @hits = (); ... for ($i = 0; $i < $len; $i++) { if (substr($doword,$i,1) ne "-") { substr($pat,$i,1) = "="; } else { substr($pat,$i,1) = '-'; } if (substr($doword,$i,1) eq ":") { substr($pat,$i,1) = substr($ +doword,$i,1); } if (substr($doword,$i,1) eq "'") { substr($pat,$i,1) = substr($ +doword,$i,1); } if (substr($doword,$i,1) eq ",") { substr($pat,$i,1) = substr($ +doword,$i,1); } if (substr($doword,$i,1) eq ".") { substr($pat,$i,1) = substr($ +doword,$i,1); } if (substr($doword,$i,1) eq "!") { substr($pat,$i,1) = substr($ +doword,$i,1); } if (substr($doword,$i,1) eq "?") { substr($pat,$i,1) = substr($ +doword,$i,1); } if (substr($doword,$i,1) eq "\"") {substr($pat,$i,1) = substr($ +doword,$i,1); } if (substr($doword,$i,1) eq "_") { substr($pat,$i,1) = substr($ +doword,$i,1); } for ($j = 0; $j < 26; $j++) { if (substr($doword,$i,1) eq $letters[$j]) { $hits[$j]++; } } } # (end of first big "for loop" for ($j = 0; $j < 52; $j++) { if (defined $hits[$j]) { if ($hits[$j] > 1) { $got_a_pattern = 1; } } } # (end of this little "for loop" if ($got_a_pattern) { ...
Apart from those comments being a waste, I think all those calls to substr could be replaced with something like this:
... for my $chr ( split //, $doword ) { $pat .= ( $chr =~ /\W/ ) ? $chr : '='; for my $ltr ( @letters ) { $got_a_pattern++ if ( $chr eq $ltr ); } } if ($got_a_pattern) { ...
One other nit-pick, in the "extractTemplates" sub:
foreach (@template2) { $_ =~ tr/ //d; if ($_ eq " ") { next; } push @template,$_; }
Notice how the "if" condition there can never return true, because all the spaces in the string have been removed by the previous "tr///"; meanwhile, you are able to push empty strings onto your @template array. Maybe you want it to be like this?
tr/ //d; push @template, $_ if ($_); # true when $_ is not an empty s +tring
But I don't know what difference it makes in how things actually work. I noticed that if you hit the enter key more than once, you get extra spacing in some of the strings being displayed (but fixing that "if" condition didn't change this behavior). Anyway, good luck with that.

In reply to Re^2: Tk cryptogram (no, not cryptography) by graff
in thread Tk cryptogram (no, not cryptography) by graff

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2023-02-03 06:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I prefer not to run the latest version of Perl because:







    Results (24 votes). Check out past polls.

    Notices?