By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,710 Members | 1,970 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,710 IT Pros & Developers. It's quick & easy.

Translate characters into variable

P: 1
Hi,

I would like to translate (Encrypte) a code from a variable.
This code is made of 3 numbers and substitution must respect a rule according number position.
For exemple:
If number 1 is the first position in the code, it must be translated to A
If number 1 is the second position in the code, it must be translated to B
If number 1 is the third position in the code, it must be translated to C

If number 0 is the first position in the code, it must be translated to Z
If number 0 is the second position in the code, it must be translated to Y
If number 0 is the third position in the code, it must be translated to X

If number 2 is the first position in the code, it must be translated to M
If number 2 is the second position in the code, it must be translated to N
If number 2 is the third position in the code, it must be translated to P

If the code is 102, translated code will be AYP

I have written following code but it doesn't run.

Expand|Select|Wrap|Line Numbers
  1. my $EncodedLockJob=0;
  2.  
  3. my LockJob0="AZM";
  4. my LockJob1="BYN";
  5. my LockJob2="CXP";
  6.  
  7. my $LockJobLength=3;
  8.  
  9. my LockJobCharIndex;
  10. my LockJobChar;
  11. my LockJobN;
  12. for ($LockJobCharIndex = 0; $LockJobCharIndex < $LockJobLength; $i++) {
  13. $LockJobChar = substr(102, LockJobCharIndex, 1);
  14. if ($LockJobChar == "0")
  15. { $LockJobN = $LockJob0; }
  16. elsif ($LockJobChar == "1")
  17. { $LockJobN = $LockJob1; }
  18. else ($LockJobChar == "2")
  19. { $LockJobN = $LockJob2; }
  20. $EncodedLockJob = $EncodedLockJob + substr($LockJobN, $LockJobCharIndex, 1);

Thanks for your help
Jul 1 '08 #1
Share this Question
Share on Google+
1 Reply


KevinADC
Expert 2.5K+
P: 4,059
You need a '$' in front of your scalar variables, like here:

Expand|Select|Wrap|Line Numbers
  1. my LockJob0="AZM";
  2. my LockJob1="BYN";
  3. my LockJob2="CXP";
  4.  
should be:

Expand|Select|Wrap|Line Numbers
  1. my $LockJob0="AZM";
  2. my $LockJob1="BYN";
  3. my $LockJob2="CXP";
  4.  
fix all of those errors and retry your code.
Jul 2 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.