Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Re: How can I populate attributes of a hash into another ?

by BrowserUk (Pope)
on Jul 19, 2013 at 10:52 UTC ( #1045332=note: print w/replies, xml ) Need Help??

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

As others have also pointed out, you cannot transparently 'inherit' one hash from another; but wouldn't

print $chapter{book}{name};

Be both acceptable and superior as its clear that it's the book's name, not the chapter's name, being printed

(Also, you could then use 'title' for both the title of the book and the title of the chapters if you wanted to):

#! perl -slw use strict; my %book = ( 'name' => 'abc', 'author' => 'monk', 'isbn' => '123-890', 'issn' => '@issn', ); my %chapter = ( 'book' => \%book, 'title' => 'xyz', 'page' => '90', ); print $chapter{book}{name}; __END__ C:\test>junk82 abc

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1045332]
[sierpinski]: thanks LanX that helps
[haukex]: the first index is always 0 - $#array gives you the last index in @array
[sierpinski]: gotcha, thanks
[LanX]: length = last index +1
[Eily]: yes LanX, both Metz and Nancy have a train station, it's just not the for the TGV
[LanX]: but the one in Metz is pretty! ;-p

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (13)
As of 2017-12-13 16:08 GMT
Find Nodes?
    Voting Booth?
    What programming language do you hate the most?

    Results (369 votes). Check out past polls.