horshack has asked for the wisdom of the Perl Monks concerning the following question:
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:
Help is very much appreciated! Thanks!#!/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"; }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: deep copy, not deep create
by saintmike (Vicar) on May 25, 2004 at 20:46 UTC | |
by ryantate (Friar) on May 27, 2004 at 18:18 UTC | |
Re: deep copy, not deep create
by eclark (Scribe) on May 25, 2004 at 21:50 UTC | |
Re: deep copy, not deep create
by dfaure (Chaplain) on May 26, 2004 at 08:18 UTC | |
Re: deep copy, not deep create
by bsb (Priest) on May 25, 2004 at 23:12 UTC |
Back to
Seekers of Perl Wisdom