in reply to Re^2: How to create variables for each hash key that has a value.
in thread How to create variables for each hash key that has a value.
This is a misconception, a variable must already exist to be tested the way you do (at least under use strict ) , but it can hold a false value if you wanna disable the block.
It looks like all var-names are known beforehand, otherwise you wouldn't be able to write code testing it!
hence you are free to write
our @arr_0 = @{ $hash{arr_0} // [] } ; our $scal_1 = $hash{scal_1} ;
both will be false if missing.
BTW use exists not defined to test hash elements.
still a very weird requirement, about how many variables are we talking?
Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery
FootballPerl is like chess, only without the dice
|
|---|