Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Some things I noticed when reading through your code...

Both your encryption and your decryption dictionaries have duplicate entries. Of course, only one of these (the last) will be used as the key in the hash. After seeing a couple, I wrote a script to find all duplicates. This is the output:

Plain words with multiple translations: EXCEPT: NEH-DIH, NA-WOL-NE HIGH: WO-TAH, EXPLOSIVE SUPPLY: NAL-YEH-HI, SHIP TANK: CHAY-DA-GAHI, DESTROYER Code words with multiple translations: AH-DEEL-TAHI: DEMOLITION, DETONATOR ALI-KHI-HO-NE-OHA: ELEVATE, TERRACE ALTH-AH-A-TEH: CLASS, TYPE BIH-TSE-DIH: BEFORE, PREVIOUS BILH: CONSIST, WITH BOSH-KEESH: SHORT, SIDE CHA-GEE: THE, THEY CLO-DIH: FIELD, OUT IL-DAY: ARRIVE, REACH KUT: NOW, PRESENT, READY NAHL-KIHD: CALIBER, DEGREE NAZ-PAS: ROUND, SURROUND NEH-DIH: BUT, EXCEPT SHIL-LOH: EXPEDITE, IMMEDIATELY, QUICK SHIP: MERCHANT, SUPPLY TA-A-TAH: ALL, ENTIRE TAH-BAHN: BEACH, SHORE WHO-NEH: REPORT, REVEAL WO-CHI: FLARE, ILLUMINATE

You can use Carp's croak (and carp) instead of die (and warn) to help the user of your module to find where things went awry in his code.

tr works with character ranges, not regular expressions.

Why use indexes in your foreach loops? You can use (implicit) aliases for the current element, leading to clearer and less cluttered code, eg this chunk from your encrypt sub:

my @words = split /\s+/, $str; foreach my $word (@words) { $word = $CDICT{$word}, next if exists $CDICT{$word}; my @letters = split //, $word; foreach (@letters) { next if /\d/; if (exists $CALPHA{$_}) { $_ = $CALPHA{$_}->[ rand @{$CALPHA{$_}} ]; } else { croak "Letter '$_' not found in encryption dictionary"; } } $word = join ' ' => @letters; } return join ' ' => @words;

— Arien


In reply to Re: Crypt::Navajo by Arien
in thread Crypt::Navajo by Cybercosis

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?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2024-03-28 20:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found