in reply to condense conditional
Instead of using a conditional, you could just store things in iteratively deeper hashes until you run out of elements in @data:
sub store_data { my( $root, $value, @key ) = @_; while( @key > 1 ) { $k = shift @key; $root->{ $k } ||= {}; $root = $root->{ $k }; }; $root->{ $key[0] } = $value; } store_data( $devstats, $value, @data );
Update: Code was missing a line
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: condense conditional
by hippo (Archbishop) on Sep 12, 2018 at 13:31 UTC |