in reply to Re^4: Confused about "unitialized value" warning
in thread Confused about "unitialized value" warning
why is that in some cases I have to use $ and some cases @?
$array refers to an element of an array. It must be followed by an index, like $array[3] and $array[$i].
@array referes to the entire array. For example scalar(@array) returns the number of elements in the array, and @a = @b copies the array.
@array can also be used to return an array slice. For example, @s = @array[1, 5 .. 7, $i] is the same as @s = ($array[1], $array[5], $array[6], $array[7], $array[$i]).
Basically, use $ when the return type is a scalar, and @ when the return type is a list/array.
Therefore $matrix[$ab][3]{_PARTNERS} is the appropriate choice here.
Examples: $count = scalar(@matrix); $count = @matrix; # scalar() is optional since we're assigni +ng to a scalar. $count = $#matrix + 1; $first_row = $matrix[0]; # this is a reference, rememeber.. @first_row = @$first_row; # dereference it. @first_row = @{$first_row}; # dereference it. @first_row = @{$matrix[0]}; # dereference it. $count_of_first_row = scalar(@first_row); # scalar() is optional h +ere. $count_of_first_row = scalar(@{$matrix[0]}); # scalar() is optional h +ere. $first_field_of_second_row = $matrix[1][0]; $first_field_of_second_row = $matrix[1]->[0]; # this is what you are r +eally doing.
Lets say if I have a variable that is supposed to look like this: Evan_PARTNERS and I'm trying to declar it by using the matrix variable
I don't understand the question. but since you're dealing with a single element of your datastructure, you'd be using $, not @.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: @array vs $array
by xspikx (Acolyte) on Aug 18, 2004 at 19:17 UTC |