Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Why not make your own function:</p> <pre><code>use strict; use warnings; sub make_hash (@) { my %h; my @unresolved; while ( @_ ) { my ( $key, $value ) = splice( @_, 0, 2 ); next unless defined $value; if ( not ref( $value ) and my ( $ref ) = $value =~ /^ref:\s*(.*\S)\s*$/ ) { if ( defined( my $v = $h{ $ref } )) { $h{ $key } = $v; } else { push @unresolved, [ $key, $ref ]; } } else { $value =~ s/^lit://; $h{ $key } = $value; } } $h{ $_-&gt;[0] } = $h{ $_-&gt;[1] } foreach grep { exists $h{ $_-&gt;[0] }; } @unresolved; return wantarray ? %h : \%h; } </code></pre> <p>To demonstrate some of the power:</p> <pre><code>my %hash = make_hash( 'key1' =&gt; 'value1' , 'key2' =&gt; 'value2' , 'key3' =&gt; 'ref:key1' , 'key4' =&gt; 'lit:ref:key2' , 'key5' =&gt; 'lit:lit:ref:key3' ); </code></pre> <p>The <code>lit:</code> prefix covers the case of "What if I <em>really</em> wanted to pass a value that is a non-reference as <code>'ref:so-and-so'</code>? It also is recursive in answering, "What if I direly need to make a value 'lit:xzy'. </p> <p>I've done this and I've also blessed a reference to a passed piece of data to a <code>Lit</code> class or something along those lines. </p> <pre><code>sub Ref ($) { bless \shift, 'Ref' } </code></pre> <p>And then in the <code>make_hash</code> routine you'd just check for <code>ref( $value ) eq 'Ref'</code>. And specify it like the following: </p> <pre><code>my %hash = make_hash( 'key1' =&gt; 'value1' , 'key2' =&gt; 'value2' , 'key3' =&gt; Ref 'key1' ); </code></pre> <p>There are many ways to make Perl act like you wish it did. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload