http://qs1969.pair.com?node_id=11145045


in reply to Deferring variables

Sorry, I initially misunderstood your question, but reading some other replies helped.

(my main processor is (st)ill suffering from a virus attack ;-)

I tried aliasing, but no joy, after the first level you have far too much trouble maintaining.

I tried refs on hash elements, it worked but was a bit too fickle, if the data structure changed.

I tried just one data structure, denoting the links with special values like \"margin" , but again too much trouble maintaining such a mangled structure.

My suggestion is to keep it simple, an additional hash %def maps to the default and you use a simple recursive get-function.

use v5.12; use warnings; use Data::Dump qw/pp dd/; my %def = ( 'margin-left' => 'margin-horizontal', 'margin-horizontal' => 'margin', # ... ); my %par = ( 'margin' => 42, ); sub get { my $key = shift // return "UNDEFINED"; # or whatever error mecha +nism you prefer $par{$key} // get( $def{$key} ) } say get("margin-left"); # 42 $par{'margin-horizontal'} = 666; say get("margin-left"); # 666 undef $par{'margin-horizontal'}; say get("margin-left"); # 42 say get("TYPO"); # UNDEFINED

please note that I also preferred undef over "a"

Otherwise you can easily change the get code with a ternary

$par{$key} ne "a" ? $par{$key} : get( $def{$key} );

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery