Mark In The Netherlands wrote:
> 
> Hello all,

Hello,

> I am hoping that someone can help me out with my syntax regarding the use of
> associative arrays.  Let's suppose that I create the following object:
> 
> my %family = (
>       'mark' => {
>             "tim" => {"sex","male","age","16"},
>             "tracy" => {"sex","female","age","12"},
>             "chantal" => {"sex","female","age","11"}
>             },
>       'john' => {
>             "rob" => {"sex","male","age","10"},
>             "sarah" => {"sex","female","age","5"},
>             "ellen" => {"sex","female","age","3"}
>             },
>       'fred' =>{
>             "bob" => {"sex","male","age","3"}
>             }
>       );

If you use the => operator you don't need to quote a \w only string on
the left and you don't need to quote numbers.

my %family = (
      mark => {
            tim     => { sex => 'male',   age => 16 },
            tracy   => { sex => 'female', age => 12 },
            chantal => { sex => 'female', age => 11 },
            },
      john => {
            rob   => { sex => 'male',   age => 10 },
            sarah => { sex => 'female', age => 5 },
            ellen => { sex => 'female', age => 3 },
            },
      fred =>{
            bob => { sex => 'male, age => 3 },
            },
      );


> The print command below seems to work fine:
> 
>  print $family{"mark"}->{"chantal"}->{"age"} . "\n";

You don't need to quote \w only keys and the -> operator is optional in
this case.

   print "$family{mark}{chantal}{age}\n";



> The following two commands do not work as (I) expected...
> 
> my %foobar = %family{"mark"};

You have to dereference the array reference stored in $family{mark}.

my %foobar = %{$family{mark}};


> print $foobar{"chantal"}->{"age"} . "\n";
> 
> I am trying to copy the "mark" sub array into a new variable (called
> %foobar).  What am I doing wrong?  There seems to be an issue with
> evaluation, references or pointers.
> 
> Many Thanks for any brief explanations of how the referencing works.  I have
> not been able to find any good documentation with google on this subject.

The documentation should be installed on your hard disk when you
installed Perl.

perldoc perldsc
perldoc perldata
perldoc perlref



John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to