s/this/that/ s#this#that# s#this# "th" . "at" #e <-- the /e means (e)valuate the RHS before do +ing substitution # so the LHS of our RE is just this ^ begin string ( begin capture into $1 \d{16} 16 digits ) end capture into $1 # when we get a match of 16 digits at the begining of the string then +we have 2 events. # first $1 contains them and # second the RHS of the RE gets evaluated. $_ = 1; # set a var to $1 so we can modify it (can't do to $1 as +read only) tr/0-9/A-J/; # transliterate contents of $_ aka $1 $_; # perl will eval this with the net result that # our 'that' result is $_ which duly gets used # to replace our original digits

/e is quite handy at times. The reason we need the naked $_ at the end of the RHS is because when perl evaluates a function (like the RHS) the return value is the last thing Perl evaluated. Without the $_ this would be the return value from tr which is not the transliterated string itself but rather the integer count of the number of transliterations. So we put the $_ there. You could put "$_ hello" or anything else you liked and that is what would get subbed in.

cheers

tachyon


In reply to Re: Re: Re: Re: Re: Simple Encryption question by tachyon
in thread Simple Encryption question by rman

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.