Making Perl's "specific declarations" as variable -


i looking sort of solution if following setup can interpreted formal declaration of variables , if possible. have :

my $str_1 = "{cow}" ;  $str_2 = "{cow}{black}{tasty_milk}"; 

what want :

(based on above variable string possible initialize hash directly, :)

my %hash=();  $hash."*some operator* on $str_i"  = 'initialized' ; 

this "some operator" should make $hash recognize hash declared earlier. i.e input specific hash initialization.

ps: don't want write function work on string , information initialize hash.

say had following input instead:

my @path = qw( cow black tasty_milk ); 

then can use following:

use data::diver qw( diveval );  diveval(\%hash, map \$_, @path) = 'value'; 

so, data::diver, get:

use data::diver qw( diveval );  $str =~ /^(?:\{\w+\})+\z/    or die("unrecognized format");  @path = $str =~ /(\w+)/g; diveval(\%hash, map \$_, @path) = 'value'; 

without module:

sub dive_val :lvalue { $p = \shift;  $p = \( $$p->{$_} ) @_;  $$p }  $str =~ /^(?:\{\w+\})+\z/    or die("unrecognized format");  @path = $str =~ /(\w+)/g; dive_val(\%hash, @path) = 'value'; 

Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -