Hi All,

am new to Perl. I'm followig this tutorial,

http://www.cs.unc.edu/~jbs/resources/perl/perl-basics/variables.html

and am confused as to why the below shows examples with $ and some with % at the beginning of the statement. When it says, "Perl uses the "percent" symbol and curly braces with respect to the name of an associative array as a whole". Am I to assume that either is fine, when defining associative arrays.? Cheers.

Mark Sargent.

%name{}
   /associative array/ ; a special, 2-dimensional array, ideal for
   handling attribute/value pairs. The first element in each row is a
   |key| and the second element is a value associated with that key.
   Perl uses the "percent" symbol and curly braces with respect to the
   name of an associative array as a whole, whereas individual elements
   within an array are referred to as scalars, although the index is
   still placed in curly braces (unlike the shift in nomenclature used
   for arrays). Instead of using numbers to index an associative array,
   key values, such as $name{"QUERY_STRING"}, are used to reference the
   value associated with that particular key, i.e., QUERY_STRING. Since
   the associated value is a scalar, the variable has a $ prefix.

$aAA{"A"} = 1;  # creates first row of assoc. array
$aAA{"B"} = 2;  # creates second row of assoc. array
%bAA = %aAA;  # creates new assoc. array and gives it values of %aAA
$aAA{"A"} = 3;  # changes the value of first item from 1 to 3
%aAA = ("A", 1, "B", 2);  # same as first two stmts., above


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to