#!/usr/bin/perl use strict; my ($hash); $hash->{one}{two}{three} = 'before'; print "$hash->{one}{two}{three}\n"; changehash($hash, [qw(one two three)], 'after'); print "$hash->{one}{two}{three}\n"; #----------------------------------------------------------- sub changehash { my ($node, $keys, $val) = @_; my $key; my $last = pop(@{$keys}); for $key (@{$keys}) { if (defined ($node->{$key})) { $node = $node->{$key}; } else { print STDERR "Unknown key: $key\n"; return; } } if (defined ($node->{$last})) { $node->{$last} = $val } else { print STDERR "Unknown key: $last\n"; return; } }