Note that there are some explanatory texts on larger screens.

plurals
  1. POKeys that spring into existence if checked with exists
    primarykey
    data
    text
    <p>If a perl-hash is declared like so:</p> <pre><code>use warnings; use strict; my %h; </code></pre> <p>I can then check for the existence of keys within this hash with <code>exists</code>:</p> <pre><code>if (exists $h{k3}) { print "k3 exists\n"; } else { print "k3 doesn't exist\n"; } </code></pre> <p>Since <code>k3</code> does not exist, the script prints <code>k3 doesn't exist</code>.</p> <p>I can also check for the existence <code>ka</code> in <code>k3</code>:</p> <pre><code>if (exists $h{k3}{ka}) { print "k3 ka exists\n"; } else { print "k3 ka doesn't exist\n"; } </code></pre> <p>Unfortunately, this creates the key <code>k3</code>, so that another </p> <pre><code>if (exists $h{k3}) { print "k3 exists\n"; } else { print "k3 doesn't exist\n"; } </code></pre> <p>now prints <code>k3 exists</code>.</p> <p>This is a bit unfortunate for my purposes. I'd rather not want perl to create the <code>k3</code> key.</p> <p>I can, of course, check for <code>ka</code> within <code>k3</code> with something like </p> <pre><code>if (exists $h{k3} and exists $h{k3}{ka}) </code></pre> <p>which doesn't create the key <code>k3</code>. But I wonder if there is a shorter (and imho cleaner) way to check for <code>ka</code> within <code>k3</code>.</p> <p><strong>Edit</strong> The question was <em>marked as duplicate</em>. Unfortunately, the only answer in the referred question that mentions <code>no autovivification</code> has only one upvote there, and is not marked as accepted answer. For my purposes, the <code>no autovification</code> is the feature I needed to know (and that I was unknowingly after). So, I leave my question here as I think the accepted answer in the other question is not the optimal one.</p> <p>Unfortunatly, nobody so far answered with <code>no autovification</code> which I would like to accept. I might therefore answer my own question.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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