Yes, after I posted, I realized that I hadn't addressed the multi-level hash issue. I didn't pursue it because I was sure it didn't matter. However, I did some testing and was shocked to find that Perl's autovivification can trigger a tied object's STORE method. I guess I shouldn't have been shocked.

So, yes, you can access a key in an unusual way and cause things to be created, unfortunately. I've long (very long) wanted a pragma to disable autovivification and this makes me want it that much more.

However, if you just attempt to fetch a single item (key or value) from the registry with Win32::TieRegistry, then it won't create anything in the registry.

Trying to fetch something that doesn't exist and using it directly in an lvalue context (such as chaining another fetch onto it) can cause stuff to be created. And, as I've noted elsewhere, exists has no magic powers for preventing such autovivification. It can prevent a sneaky lvalue context from suprising you (exactly the same as scalar or any number of other things can do).

But simply avoiding an lvalue context is also enough. For example:

my $key= $Registry->{"..."};

Or even:

if( $Registry->{"..."} ) {

is never going to create anything in the registry.

Update: I should add an option to the module to die if you try to create by assigning an empty hash ref because that would prevent autovivification.

- tye        


In reply to Re^3: In Win32::TieRegistry, what is the best way to tell if a registry variable exists? (STORE) by tye
in thread In Win32::TieRegistry, what is the best way to tell if a registry variable exists? by DrWhy

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.