I want to have an inherited datastructure in a configuration module I write. There is a bavarian, who shall be a german, who shall be a european.

First she will be a european with all attributes, then the german attributes will be added. Attributes which do not override the european attributes stay. Now the bavarian attributes which override the ones being in the structure.

This looks like deep copy where I found a long thread. But this seems not to be a problem of creating a new data structure (module Clone, Storage::dclone), but to build an existing up and up. I wrote this code to demonstrate:

#!/usr/bin/perl use strict; use Data::Dumper; my %europe = ( skin => "euro-white", language => { default => "euro-englisch", instrument => "euro-clarinet", }, politics => "euro-democratic", ); my %german = ( skin => "de-white", language => { default => "de-german" } ); my %bavarian = ( skin => "bav-white", language => { default => "bav-bavarian" } ); # this is not enough, german/language overwrites # the complete hash of euro/language my %woman = ( %europe, %german, %bavarian ); print Dumper(\%woman); # result is this: # $VAR1 = { # 'skin' => 'bav-white', # 'politics' => 'euro-democratic', # 'language' => { # 'default' => 'bav-bavarian' # ** this is not here: instrument => "euro-clarinet", # } # }; unless ($woman{language}->{instrument}) { die "Error: Language instrument is not there"; } else { print "It worked\n"; }
Help is very much appreciated! Thanks!

In reply to deep copy, not deep create by horshack

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":