473,387 Members | 1,456 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Translate characters into variable

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
1 1070
KevinADC
4,059 Expert 2GB
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

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

Similar topics

7
by: Bengt Richter | last post by:
Just thought None as the first argument would be both handy and mnemonic, signifying no translation, but allowing easy expression of deleting characters, e.g., s = s.translate(None,...
1
by: Xeon | last post by:
Hi, I'm trying to replace spaces with %20 with help of translate, but not successfull. Here's a node in the xml file : <title>This is some test title</title> The xsl code I'm using : ...
9
by: JezB | last post by:
Is there anything in the framework which will help translate accented characters in strings to their standard counterparts? eg. "Gráda" to "Grada"
1
by: kennethfine | last post by:
I'm transitioning from ASP development, please excuse these basic questions. One thing I did often in ASP was create a "translate" function to render one string to another, strip out excess...
1
by: peterbe | last post by:
This has always worked fine for me. Peter fine Now if I do it with a unicode string: Traceback (most recent call last): File "<stdin>", line 1, in ? File "/usr/lib/python2.4/string.py", line...
3
by: amija0311 | last post by:
Hi, I am new using DB2 9.1 database by windows base. I want to query the data that contain string then translate the string into integer using DB2. The problems is If the data is null, i got the...
4
by: destroooooy | last post by:
Hi folks, I'm finding some (what I consider) curious behavior with the string methods and the forward slash character. I'm writing a program to rename mp3 files based on their id3 tags, and I want...
4
by: kovariadam | last post by:
Hi, Does anybody know why i get this error: SQL0176N The second, third or fourth argument of the TRANSLATE scalar function is incorrect. SQLSTATE=42815 with this query: SELECT...
4
by: Bob | last post by:
Is there an easy way to translate odd UTF8/16 characters (like letters with umlauts, vowels with accent symbols above) into the closest 'look-alike' lower ascii equivalent (A-Z, a-z)? This is...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.