Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What Kind Of Array Is This?

Status
Not open for further replies.

H100

Programmer
Joined
Sep 21, 2007
Messages
2
Location
US
N00b question, sorry... I'm porting some Perl code to Java, and I came across code like this:

$d['A3'] = 63.6;
$d['B1'] = 34.6;
$d['C4'] = 7.2;
$d['B'] = 49.2;

My first assumption was that this is something like a hashtable or associative array, where the value (for instance) of $d['C4'] is 7.2. However, any time I try to run the Perl script and print the value of any item in the array based on what I thought was the "key" ('C4'), I always get the value of the last item listed - in the case above, everything returns 49.2.

Can anyone explain this construct? I've searched online and found nothing.

Thanks in advance for any help!

H100


 
the code you posted is not any kind of perl code. If it is a hash the keys are wrapped in curly brakets {}, not square brackets []:


$d{'C4'} = 7.2;

arrays can only use a number inside the square brackets to access the element that the number is the index of:

$d[4] = 7.2;

or a scalar that is a number:

$i = 4;
$d[$i] = 7.2;



------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
KevinADC said: "the code you posted is not any kind of perl code"

Kevin, thank you so much for your quick reply. Believe me, that possibility actually crossed my mind... scary...

Unless there is some kind of Perl extension out there that allows for this weird type of array notation, I'm going to have to consider the legacy code flawed and scrap it.

Thanks again!
H100

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top