So how is $bound := %data{$key} different from $bound = \%data{$key}

In the first case, $bound becomes another name for %data{$key}. In the second case, $bound simply stores a reference to %data{$key}.

That one extra level of indirection may not seem important, but consider what happens later in the code when we write:

$bound = $nuclear_reactor_shutoff_command;
In the first case, the shutoff command goes into the entry %data{$key}. In the second case, the reference to %data{$key} is (silently!) replaced by the shutoff command, and %data{$key} itself is not updated at all.

Which is better? Well, of course, it depends on what you were trying to achieve. But, with the departure of typeglobs, we need to have some way to do the former, and that way is going to be binding.

And, indeed, as I mentioned in E3, binding has a couple of major advantages over typeglobbing: it's typesafe(r), and bound variables can be lexically scoped.


In reply to Re: Re: Re (tilly) 2: Comprehending Binary := by TheDamian
in thread Comprehending Binary := by swiftone

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.