in reply to Re^3: Confused about "unitialized value" warning
in thread Confused about "unitialized value" warning

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, why is that in some cases I have to use $ and some cases @? ${matrix}[$ab][3]{_PARTNERS} @{matrix}[$ab][3]{_PARTNERS}

Replies are listed 'Best First'.
@array vs $array
by ikegami (Patriarch) on Aug 18, 2004 at 18:09 UTC
    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 @.

      Thanks for all your help.