<?xml version="1.0" encoding="windows-1252"?>
<node id="954551" title="Re^4: RFC: Tutorial: use strict; now what!?" created="2012-02-17 10:44:26" updated="2012-02-17 10:44:26">
<type id="11">
note</type>
<author id="704000">
Xiong</author>
<data>
<field name="doctext">
&lt;blockquote&gt;&lt;i&gt;I am trying to follow this as I use hashes all over the place. What exactly is a soft reference.&lt;/i&gt;&lt;/blockquote&gt;

&lt;p&gt;[tangent], you'll get plenty of explanations of symbolic references. But even after you understand them well it may not be clear how &lt;b&gt;hashes&lt;/b&gt; come into this, in almost the same breath. 
&lt;/p&gt;

&lt;p&gt;To recap, [moritz] [id://952448|offered hashes] as an alternative to hard references. There was some discussion of this and [JavaFan] [id://952626|noted] hashes can invite some of the same issues &lt;c&gt;strict 'refs'&lt;/c&gt; is meant to avoid. You may not see the connection; it took me a moment to pick it up. 
&lt;/p&gt;

&lt;p&gt;Seen one way, &lt;c&gt;use strict;&lt;/c&gt; is a typo-catcher. In the simple case:
&lt;/p&gt;

&lt;c&gt;
our $x13 = 'foo';
print $x31;
&lt;/c&gt;

&lt;p&gt;... may not work as you expect because you really meant to type &lt;c&gt;$x13&lt;/c&gt; both times. But &lt;c&gt;use strict;&lt;/c&gt; will complain that you did not declare &lt;c&gt;$x31&lt;/c&gt; and so the typo is caught. 
&lt;/p&gt;

&lt;p&gt;If you attempt to take a hard reference and make a typo, you'll get an error, too. But if you take a &lt;i&gt;symbolic&lt;/i&gt; reference and don't &lt;c&gt;use strict;&lt;/c&gt; then you will not get early notice of your typo.
&lt;/p&gt;

&lt;p&gt;Where hashes begin to resemble (in a certain mental state) symbolic references is when you start stuffing a lot of unrelated data into a hash with literal keys; and then later you want to take something out: 
&lt;/p&gt;
&lt;c&gt;
my %hash;
$hash{boy}             = 'Arnold';
$hash{pension_balance} = 172.50;
$hash{filehandle}      = $fh;
print $hash{pensionbalance};
&lt;/c&gt;

&lt;p&gt;The typo will not be caught, with or without &lt;c&gt;use strict;&lt;/c&gt; instead, perl will happily &lt;b&gt;autovivify&lt;/b&gt; &lt;c&gt;$hash{pensionbalance}&lt;/c&gt; for you and immediately print it... although it's &lt;b&gt;undefined&lt;/b&gt;. This can be an annoying thing to track down.  
&lt;/p&gt;

&lt;p&gt;For more on this, see [id://953289], where I demonstrate exactly this kind of risky approach... and note that it's &lt;i&gt;almost as evil&lt;/i&gt; as global variables. I would not even have mentioned it if the OP didn't seem solidly committed to globals in the first place. As questionable as it is, I still think it's better than &lt;c&gt;no strict 'refs';&lt;/c&gt;
&lt;/p&gt;
&lt;div class="pmsig"&gt;&lt;div class="pmsig-704000"&gt;
&lt;i&gt;I'm not the guy you kill, I'm the guy you buy.&lt;/i&gt; &amp;mdash;Michael Clayton
&lt;/div&gt;&lt;/div&gt;</field>
<field name="root_node">
952446</field>
<field name="parent_node">
952737</field>
</data>
</node>
