Ask a Question related to PERL Beginners, Design and Development.
-
Robert Zielfelder #1
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
..-. --..
Robert Zielfelder Guest
-
Hash
Hi, How set up functions hash in php4.3.2 thanks _________________________________________________________________ Charla con tus amigos en... -
Hash in AS 2.0
So I was about to write a hash algorythm for flash and it appears brandon hall beat me by 2 years. Since there isn't anything here, in the flash... -
hash of hash of array slices
This works Foreach ( @{$hash{$key1}{$key2}} ) This does note Foreach ( @{($hash{$key1}{$key2})} ) This gives me this error .... Can't... -
Sort a hash based on values in the hash stored as arrays of hashes
Hmm. I'm not quite sure if I got the subject right, but I'll try to explain. :-) I've got a hash of elements stored like this: $VAR1 = {... -
Another reference question (hash of hash references)
beginners, I am trying to build a hash of hash references. My problem is that I need to be able to add a key/value pair to the internal hashes...... -
Rob Hanson #2
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:robert.zielfelder@tycoelectronics.com]
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]beginners-unsubscribe@perl.org[/email]
For additional commands, e-mail: [email]beginners-help@perl.org[/email]
Rob Hanson Guest
-
Robert Zielfelder #3
RE: Hash of Hash
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:rhanson@aptegrity.com]
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:robert.zielfelder@tycoelectronics.com]
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]beginners-unsubscribe@perl.org[/email]
For additional commands, e-mail: [email]beginners-help@perl.org[/email]
Robert Zielfelder Guest



Reply With Quote

