#!/usr/bin/perl use warnings; use strict; package childmodul; sub new { my $classname = shift; my $self = {}; $self->{ScriptParam}->{ScriptName} = $0; $self->{ScriptParam}->{Version} = "v.01"; $self->{ScriptParam}->{Hilfe}->{Usage} = "ruf mich mal richtig auf"; $self->{ScriptParam}->{Hilfe}->{Message} = 'rufe mal nach Mutti'; $self->{Runtime}->{ApplName} = "TestClass"; $self->{Runtime}->{Caller} = $^O =~ /win32/i ? $ENV{USERNAME} : $ENV{USER}; $self->{Runtime}->{Loglevel} = "höher geht nicht"; $self->{Runtime}->{RootPath} = "ganz oben"; $self->{Runtime}->{StartTime} = "am Anfang"; $self->{DBParam}->{RegPar} = "test"; $self->{DBParam}->{dbSession}->{ApplName} = "testhash"; $self->{DBParam}->{dbSession}->{Action} = "insert"; $self->{DBParam}->{dbSession}->{runtime}->{dbTable} = "INIT_REG"; return bless($self, $classname); } sub set_Data { my $self = shift; my $val = shift; my @locations = @_; # save last key my $last_location = pop @locations; # helper ref for each level inside HoHoH... my $ref = $self; for my $location ( @locations ) { # create new hash reference at this level if not already there $ref->{$location} = {} if !exists $ref->{$location}; # save reference to current level in helper ref $ref = $ref->{$location}; } # save value in last key $ref->{$last_location} = $val; } package main; my $Object1 = childmodul->new(); $Object1->set_Data('INIT_RUN', qw( DBParam dbSession runtime dbTable )); print $Object1->{DBParam}->{dbSession}->{runtime}->{dbTable} . "\n"; $Object1->set_Data('update', qw( DBParam dbSession Action )); print $Object1->{DBParam}->{dbSession}->{Action} . "\n"; $Object1->set_Data('debug', qw( Runtime Loglevel )); print $Object1->{Runtime}->{Loglevel} . "\n";