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 @.


In reply to @array vs $array by ikegami
in thread Confused about "unitialized value" warning by xspikx

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.