CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Beginner: Translation Hash: Edit Log


Dec 11, 2012, 10:38 AM

Views: 1442
Translation Hash


I have a paragraph of text in a file that I am to translate using a translation hash. I am completely stalled on approach and on using hash keys and values as variables.

The translation hash looks like this:

%tr_hash = ( 
a => l
b => b
c => e
d => z
e => g
f => s
g => d
h => w
i => f
j => h
k => q
l => u
m => o
n => k
o => n
p => p
q => y
r => r
s => j
t => a
u => t
v => c
w => v
x => x
y => m
z => i

The message I am to translate looks something like this:

kernndg vlk bgaagr ajlf jwk vnrz. jg zwz wa luu 
(snipped to prevent really long lines)

So basically it is a letter substitution where I replace $v with $k.

My problem is I don't know how to use hash keys and values as variables. For example s/$v/$k

Next, I'm not sure how to even approach it as I think I would have to loop through the message text while looping through the hash keys for the substitution. So I think I would have a while statement for the file and a foreach statement for the hash but everytime I try to code it I can't seem to progress beyond the "hmmmmm: stage.

Thanks for any feedback.

(This post was edited by cyberfarer on Dec 11, 2012, 10:42 AM)

Edit Log:
Post edited by cyberfarer (Novice) on Dec 11, 2012, 10:42 AM

Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives