Skip to content

Instantly share code, notes, and snippets.

@hirafoo
Created March 19, 2010 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save hirafoo/337522 to your computer and use it in GitHub Desktop.
Save hirafoo/337522 to your computer and use it in GitHub Desktop.
use strict;
use Data::Dumper;
sub foo {
my ( $a_ref, $key, $value ) = @_;
my $a_ref2 = \$a_ref;
$a_ref2 = \$$a_ref2->{$_} for split /\./, $key;
$$a_ref2 = $value;
return $a_ref;
}
my $ref = {
foo => {
bar => {
baz => 1,
},
},
};
$ref = foo( $ref, 'foo.bar.baz', 100 );
warn Dumper $ref;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment