<?xml version="1.0" encoding="windows-1252"?>
<node id="1004386" title="Re^3: elsif statement not being evaluated" created="2012-11-18 03:35:05" updated="2012-11-18 03:35:05">
<type id="11">
note</type>
<author id="747201">
afoken</author>
<data>
<field name="doctext">
&lt;p&gt;Happens to everyone using C or languages inheriting or stealing from C. But you can make the compiler / interpreter complain loudly if you make sure the constant is on the left side of the operator:&lt;/p&gt;
&lt;c&gt;
if ($answer=42) { # $answer is now always 42
    ...
}


if (42=$answer) { # "Can't modify constant item in scalar assignment"
    ...
}

&lt;/c&gt;
&lt;p&gt;This won't help when you compare two variables, but in your case, the variables &lt;c&gt;$an1&lt;/c&gt; and &lt;c&gt;$an2&lt;/c&gt; aren't variable, but constant. So make them constant, either by using [mod://Readonly] or by using [mod://constant]:&lt;/p&gt;
&lt;c&gt;
use Readonly;
Readonly my $fortytwo =&gt; 42; # note: =&gt;, not =

...

if ($fortytwo=$answer) { # "Modification of a read-only value attempted"
    ...
}
&lt;/c&gt;
&lt;c&gt;
use constant FORTYTWO =&gt; 42; # note: =&gt;, not =

...

if (FORTYTWO=$answer) { # "Can't modify constant item in scalar assignment"
    ...
}
&lt;/c&gt;
&lt;p&gt;Or, in this trivial case, get rid of &lt;c&gt;$an1&lt;/c&gt; and &lt;c&gt;$an2&lt;/c&gt; and use 1 and 2.&lt;/p&gt;
&lt;p&gt;I prefer [mod://Readonly] over [mod://constant], because &lt;c&gt;Readonly&lt;/c&gt; just makes the variables readonly, with no surprises, whereas &lt;c&gt;constant&lt;/c&gt; (ab)uses the perl optimizer and implements the constants as functions returning a constant value. This has some nasty side effects [http://search.cpan.org/~roode/Readonly-1.03/Readonly.pm#COMPARISON_WITH_%22use_constant%22|documented in Readonly].&lt;/p&gt;
&lt;p&gt;Alexander&lt;/p&gt;
&lt;div class="pmsig"&gt;&lt;div class="pmsig-747201"&gt;
--&lt;br&gt;
Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
&lt;/div&gt;&lt;/div&gt;</field>
<field name="root_node">
1004376</field>
<field name="parent_node">
1004380</field>
</data>
</node>
