星期一 十二月 01, 2008

   It is very common , even some experienced perl developers can not tell the difference between list and array in perl. But in fact they are very different: the list is DATA , while the array is VARIABLE. Every array holds a data of list, but one list might have nothing to do with an array.

   When I learned Perl, one thing confused me is " @l = qw/a b c/ " , at that time I thought it means "@l" is a variable , and operators like "pop" or "push" can accept variables too. That's totally wrong. "pop" or "push" does not accept any "scalar dereference".  They only accept data!

   The " @l = qw/a b c/ " means there is a list, which name is 'l' and it hosts elements 'a', 'b' and 'c' .  In Perl, the name 'l' is shared by list and array. So when we use @l , we are supposed to  use list, while use '$l', we want the variable which referrers to the list named 'l'!

评论:

You are mixing up @{$A}, $A, \@A and their friends.

发表于 Daniel Cheng 在 2008年12月01日, 09:38 下午 CST #

发表一条评论:
  • HTML语法: 禁用