Hello henzcoop,

You’re nearly there. But (1) eval returns the value of the last expression evaluated; but you don’t want the number of transliterations, you want the transliterated string, which is $message. (2) Within an eval, a variable such as $message will itself be interpolated. But you want to evaluate the expression $message =~ ..., so you need to escape the $ sigil to prevent interpolation of the $message variable into the string to be evaluated.

#! perl use strict; use warnings; print "Please enter your message to be encrypted.\n"; my $message = <STDIN>; chomp($message); # generate randomized alphabet my @chars = ("A".."Z", "a".."z"); my $string; $string .= $chars[rand @chars] for 1..26; # I want to drop the random alphabet in $string into the replace-with +slot of tr// eval "\$message =~ tr/a-z/$string/;"; print "Here is your encrypted message: $message\n";

Alternatively, you can add an /r modifier to the transliteration to get it to return the transliterated value:

my $code = eval "\$message =~ tr/a-z/$string/r;"; print "Here is your encrypted message: $code\n";

See the entry for tr/SEARCHLIST/REPLACEMENTLIST/cdsr under perlop#Quote-Like-Operators.

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,


In reply to Re: secret code, transliteration prob by Athanasius
in thread secret code, transliteration prob by henzcoop

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.