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:
NOTE: And what about '@issn' in your script? Like you have it, if it is an array variable, it won't interpolate!! Just saying...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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How can I populate attributes of a hash into another ?
by hdb (Monsignor) on Jul 19, 2013 at 08:40 UTC |