#!/usr/bin/perl use warnings; use strict; use DateTime qw(); use feature qw/say switch/; package childmodul; sub new { my ($classname,$hsh_scriptParam) = @_; my $self = {%{$hsh_scriptParam}}; return bless($self, $classname); } sub set_Data { my $self = shift; my $val = shift; my @locations = @_; # save last key my $last_key = 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}; # this points to the next level down the hash tree $ref = $ref->{$location}; } # save value in last key if (ref($last_key) eq 'ARRAY') { $ref->[$last_key->[0]] = $val; } else { if (ref($val) eq 'HASH') { $ref->{$last_key} = $val->{hash}; } else { $ref->{$last_key} = $val; } } } package main; my $hsh_runtimeParam = { ScriptParam => {ScriptName => $0 || '???', Version => 'v.01' || '???', Hilfe => {Usage => 'ruf mich mal richtig auf', Message => 'rufe mal nach Mutti' }, }, Runtime => {ApplName => 'TestClass', Caller => $^O =~ /win32/i ? $ENV{USERNAME} : $ENV{USER}, Loglevel => 'höher geht nicht', RootPath => 'ganz oben' || '???', StartTime => 'am Anfang' || '???', Instanz => [ 'test1', 'test2', '11', 'array' ] }, DBParam => {RegPar => 'test', dbSession => {ApplName => 'testhash', Action => 'insert', runtime => {dbTable => 'INIT_REG'}} }, }; my $Object1 = childmodul->new($hsh_runtimeParam); my @h_keys = qw(Runtime Instanz); push @h_keys, [3]; $Object1->set_Data('hash', @h_keys ); $Object1->set_Data({hash=>{ RUN_ENDDATE => ["to_date(?,'DD.MM.YYYY HH24:MI:SS')",DateTime->now(time_zone => 'local')->strftime('%d.%m.%Y %H:%M:%S')], RUN_LOGMSG => 'Message', RUN_RC_CODE => '12' }}, qw(DBParam RunPar) ); $Object1->set_Data('update', qw( DBParam dbSession Action )); $Object1->set_Data('debug', qw( Runtime Loglevel )); print 'Ende' . "\n";