Your skill will accomplish what the force of many cannot |
|
PerlMonks |
Re^2: Converting Hashes to Objectsby haukex (Archbishop) |
on May 20, 2020 at 08:11 UTC ( [id://11116966]=note: print w/replies, xml ) | Need Help?? |
my %vars = %$rvars; A note on this: When you do this, you're creating a (shallow) copy of the hash, and if $rvars happens to be a Util::H2O object, you'd lose its methods. If that's not what you want, you'll have to work with the hash reference directly. In newer versions of Perl (>=5.22), there is an experimental feature that allows aliasing:
But since it's experimental, it's probably better to stick with $rvars->{foo} instead. Q1) How is a "setter" to be implemented? In the context of Util::H2O, getters/setters are created for every key that exists in the hash or is given as an "additional key" at the time of the h2o call. So for your $hash->x("z") to work, there'd need to be a key x in the hash or you need to specify it to the h2o function; you don't need to write your own sub x.
TIMTOWTDI, here's how I might have written it without the module:
And with the module, one can write:
In Section
Meditations
|
|