LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   perl - simple array syntax problem (https://www.linuxquestions.org/questions/programming-9/perl-simple-array-syntax-problem-179506/)

lrt2003 05-09-2004 12:44 AM

perl - simple array syntax problem
 
I'm trying to declare all the lowercase letters in the alphabet in an array, so then I can call on 'a' as '1' and 'c' as '3', etc...

This doesn't seem to work...

@lwralphabet=qw/JUNK ['a'..'z']/;
print $lwralphabet[3];

david_ross 05-09-2004 05:40 AM

Try using:
@lwralphabet=('a'..'z');
print $lwralphabet[3];

Also remember that the first item in an array is at "0" so a=0.

lrt2003 05-09-2004 06:58 AM

that works, thanks..

I was trying to get it to get the values + 1 by using a JUNK value.. however, this will suffice

david_ross 05-09-2004 01:35 PM

If you really want "a" to be one then you can use:
@lwralphabet=('Z','a'..'z');

This will make Z=0 and a=1


All times are GMT -5. The time now is 06:02 PM.