Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Set hash equal to another

Status
Not open for further replies.

CJason

Programmer
Joined
Oct 13, 2004
Messages
223
Location
US
If I have a hash of a hash, is there a way to set another hash table equal to the "hash" of the original hash table?

For example,
$hash1 => {
"stuff1" => {
"substuff1" => "hello";
"substuff2" => "goodbye";
},
"stuff2" => {
"substuff1" => "hello";
"substuff2" => "goodbye";
},
};

And I want to do something like:
%hash2 = $hash1{"stuff1"};

Is that doable? If so, can someone point me the way?

Thanks in advance!
 
Well, other than the fact that your assignment syntax is all foobarred, yes it is possible.

Code:
my %hash1 = (
   "stuff1" => {
      "substuff1" => "hello",
      "substuff2" => "goodbye",
   },
   "stuff2" => {
      "substuff1" => "hello",
      "substuff2" => "goodbye",
   },
);

my %hash2 = %{$hash1{stuff1}};
# %hash2 equals (substuff1 => 'hello', substuff2 => 'goodbye');
 
if you correct the syntax of your hash you can do something like this:

Code:
$hash1 = {
   "stuff1" => {
      "substuff1" => "hello",
      "substuff2" => "goodbye",
   },
   "stuff2" => {
      "substuff1" => "hello",
      "substuff2" => "goodbye",
   },
};
%hash2 = %{$hash1->{stuff1}};


- Kevin, perl coder unexceptional!
 
[smile]

- Kevin, perl coder unexceptional!
 
[smile]

Sometimes that's just freeky.

Amusingly enough, once again I can't help but be snarky while you're actually nice about correcting his errors. How on earth do you hold back the snark? It's awe inspiring :)
 
First, I assume everyone that asks a question is [gorgeous], then I invision them in their underwear. [spineyes]

[pacman]

- Kevin, perl coder unexceptional!
 
Hrm... interesting.

You imagine everyone is a drag queen in their underwear? And then you eat the poo of a ghost that then chases you?

I suppose everyone has their techniques. I'll give it a try [tongue]
 
First, I assume everyone that asks a question is [gorgeous]"

That kind of assumption just gets me into trouble :-)

Mike

The options are: fast, cheap and right - pick any two. [orientalbow] & [anakin]

Want great answers to your Tek-Tips questions? Have a look at faq219-2884

 
well, now that Miller has me seeing hairy chested drag-queens instead of gorgeous ladies in their undies, I'm probably going to start getting smarmy [bomb]

[flowerface]

- Kevin, perl coder unexceptional!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top