<?xml version="1.0" encoding="windows-1252"?>
<node id="1017815" title="Re^2: Why Perl boolean expression sometimes treated as lvalue?" created="2013-02-08 08:22:52" updated="2013-02-08 08:22:52">
<type id="11">
note</type>
<author id="961">
Anonymous Monk</author>
<data>
<field name="doctext">
&lt;p&gt; Interesting ... note the parens, perl parses it correctly &lt;c&gt;
$ perl -MO=Deparse,-p -le " $a= 1 &amp;&amp; 2; print $a; "
BEGIN { $/ = "\n"; $\ = "\n"; }
($a = 2);
print($a);
-e syntax OK

$ perl -MO=Deparse,-p -e "  $a &amp;&amp; $b = 3; "
Can't modify logical and (&amp;&amp;) in scalar assignment at -e line 1, near "3;"
-e had compilation errors.
(($a &amp;&amp; $b) = 3);
&lt;/c&gt;
&lt;p&gt; But there is no code to execute this  :) its default [href://http://perl5.git.perl.org/perl.git?a=search&amp;h=HEAD&amp;st=grep&amp;s=Can%27t+modify+%25s|Can't modify %s]
[href://http://perl5.git.perl.org/perl.git/blob?f=op.c#l2020]
&lt;c&gt;

2012         /* FALL THROUGH */
2013     default:
2014       nomod:
2015         if (flags &amp; OP_LVALUE_NO_CROAK) return NULL;
2016         /* grep, foreach, subcalls, refgen */
2017         if (type == OP_GREPSTART || type == OP_ENTERSUB
2018          || type == OP_REFGEN    || type == OP_LEAVESUBLV)
2019             break;
2020         yyerror(Perl_form(aTHX_ "Can't modify %s in %s",
2021                      (o-&gt;op_type == OP_NULL &amp;&amp; (o-&gt;op_flags &amp; OPf_SPECIAL)
2022                       ? "do block"
2023                       : (o-&gt;op_type == OP_ENTERSUB
2024                         ? "non-lvalue subroutine call"
2025                         : OP_DESC(o))),
2026                      type ? PL_op_desc[type] : "local"));&lt;/c&gt;</field>
<field name="root_node">
1017801</field>
<field name="parent_node">
1017804</field>
<field name="reputation">
7</field>
</data>
</node>
