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


In reply to Re: Deferring variables by LanX
in thread Deferring variables by Chuma

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.