Search code examples
perlscalar

What does this mean in perl $variable_one{$variable_two} and what is it called?


I saw this in a piece of code:

if (some_condition) {  
 $index++;  
}  
$index{$some_variable} = $index{$some_variable} + 1; 

What does $index{$some_variable} mean? And why is it used?

Thank you.

EDIT: index is defined as $index=0;


Solution

  • It's retrieving an entry in the %index hash using a key whose value is the value of $some_variable

    (Note: There may also exist a scalar named $index but it will occupy a separate namespace. That is, you can have both a hash and a scalar named index and they will not conflict.)