Hey guys,
I have a hash that is going to be used as a letter substitution key: A->B, B->F, C->J, etc. etc.
I have a message that's a scalar.
I'd love to use a regex with the hash keys and values to do this substitution in one or two lines if I can.
The alternative is to ginsu up the scalar into an array, switch each element of the array and then glue it back together into a scalar again.
Neither of these work. :(
# $mes =~ tr/(keys %codewheel)/(values %codewheel)/;
# $mes =~ tr/[keys %codewheel]/[values %codewheel]/;
Edit: Awesome, thanks guys. I recognize the \w and $1, but I didn't know how to include scalars into regex's. Thanks. Um, if we don't use the ()'s in (\w), will it scoop the whole message as one big pattern, or the whole first word or something?
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.