[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: % with perl



Robin Gerard <robin.jag@free.fr> writes:

> %loginpsswd=("gerard","12345678","jaimie","78945612","andy","45632178");
>  print $loginpsswd{"gerard"};
> print $loginpsswd{"$loginpasswd[2*$i]"};  

A hash variable is not the same symbol as an array variable. 

  %loginpasswd is a hash variable
  @loginpasswd is an array variable
  $loginpasswd{foo} says to look up a hash variable in the symbol table.
  $loginpasswd[1] says to look up an array variable in the symbol table.

The latter two syntaxes refer to two different variables. You shouldn't
let the fact that you can assign a list to a hash confused you about the
difference between an array and a hash, because they are different
things, and can't be used interchangably.

See 

  perldoc -f each
  perldoc -f keys

for information on how to iterate over hashes.

-- 
Dave Carrigan                            | Yow! Are you mentally here at Pizza
Lead Technical Architect                 | Hut??
PDA Verticals Corporation                | 
http://www.pdaverticals.com/             | 



Reply to: