This is exactly what I was after.  Not being a "real" programmer I was
tripping on syntax as usual.  Thanks for the help

Rz


.-.  --..
 -----Original Message-----
From:   Hanson, Rob [mailto:[EMAIL PROTECTED] 
Sent:   Monday, August 18, 2003 9:50 AM
To:     Zielfelder, Robert; Perl Beginners List (E-mail)
Subject:        RE: Hash of Hash

I think you mean this...

use strict;
my %thief_opt;
my @name = ("one", "two", "three");

foreach my $layer (@name) {
  $thief_opt{$layer} = {
     type     => "solid",
     origin   => "datum",
     use_arcs => "yes",
  };
}

# test with this. prints out structure to console.
use Data::Dumper;
print Dumper \%thief_opt;

The above prints this...

$VAR1 = {
          'one' => {
                     'origin' => 'datum',
                     'use_arcs' => 'yes',
                     'type' => 'solid'
                   },
          'three' => {
                       'origin' => 'datum',
                       'use_arcs' => 'yes',
                       'type' => 'solid'
                     },
          'two' => {
                     'origin' => 'datum',
                     'use_arcs' => 'yes',
                     'type' => 'solid'
                   }
        };

Rob



-----Original Message-----
From: Zielfelder, Robert [mailto:[EMAIL PROTECTED]
Sent: Monday, August 18, 2003 9:38 AM
To: Perl Beginners List (E-mail)
Subject: Hash of Hash


Greetings,

I am attempting to make a hash of hashes or something equivalent but can't
seem to get it working properly.  Here is what I have so far:

@name = ("one", "two", "three");

Foreach my $layer (@name) {
        $thief_opt = {
                $layer = {
                        type            => "solid",
                        origin          => "datum",
                        use_arcs        => "yes",
                }
        };
}

##--for test purposes simply print the vars for now

while (($key, $val) = each %$thief_opt) {
        while (($key2, $val2) = each %$val) {
                print "$key $key2 $val2;
        }
}


I am trying to create a HoH that is called %thief_opt and who's first key is
based on a list contained in an array called @name.  This bit of code seems
to work and create a HoH with the structure I want, but the problem is that
every iteration of my foreach loop steps on the previous values for
%thief_opt so that in the end I only get a HoH for the last value in @name
(which in this case is "three"). 
 To try and explain it another way,  I have a list inside of @name that
might be something like: one, two, three.  I want to make a HoH that would
look more like the following if the values of @name were constants and could
be hard coded:

$thief_opt = {
        one = {
                type            => "solid",
                origin          => "datum",
                use_arcs        => "yes",
        },
        two = {
                type            => "solid",
                origin          => "datum",
                use_arcs        => "yes",
        },
        three = {
                type            => "solid",
                origin          => "datum",
                use_arcs        => "yes",
        },
}

I would appreciate any ideas or suggestions.

Best Regards,

Robert Zielfelder









.-.  --..

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

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

Reply via email to