Created
May 20, 2016 08:53
-
-
Save xiaocang/9d51abc1f2644e3dfcb46b2cad1fed0b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl [0/3] | |
use strict; | |
use warnings; | |
use Smart::Comments; | |
my @array = qw{a b c}; | |
my $result = {}; | |
my $r = $result; | |
sub walk { | |
my $v = shift; | |
my $value = shift; | |
if ($value) { | |
$r->{$v} = $value; | |
} else { | |
$r->{$v} = {}; | |
} | |
return $r->{$v}; | |
} | |
for (0..$#array) { | |
if ( $_ == $#array ) { | |
$r = walk($array[$_], [1, 2, 3]); | |
} else { | |
$r = walk($array[$_]); | |
} | |
} | |
### $result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment