http://www.perlmonks.org?node_id=1045285


in reply to How can I populate attributes of a hash into another ?

ravi06,
I thought, a chapter should be a subset of a book and not the other way round? However, if you are sure of what you wanted, knowing that the key of hash MUST be unique, then you can do like so:

use warnings; use strict; use Data::Dumper; my %book = ( 'name' => 'abc', 'author' => 'monk', 'isbn' => '123-890', 'issn' => '@issn', ); my %chapter = ( 'title' => 'xyz', 'page' => '90', ); ## VOIR HERE my @temp_arr = keys %book; @chapter{@temp_arr} = @book{@temp_arr}; print Dumper \%chapter; print $/, $chapter{name},$/; #prints abc
NOTE: And what about '@issn' in your script? Like you have it, if it is an array variable, it won't interpolate!! Just saying...

If you tell me, I'll forget.
If you show me, I'll remember.
if you involve me, I'll understand.
--- Author unknown to me