$#a returns a magical value in lvalue contexts. (It used to always returns a magical value, but this was optimized.)

$ perl -MDevel::Peek -e'@a=qw( a b c ); sub { Dump($_[0]) }->( $#a );' SV = PVMG(0x1d36630) at 0x1cfcfd0 REFCNT = 1 FLAGS = (GMG,SMG) IV = 0 NV = 0 PV = 0 MAGIC = 0x1cf6ab0 MG_VIRTUAL = &PL_vtbl_arylen MG_TYPE = PERL_MAGIC_arylen(#) MG_OBJ = 0x1d07d10

The behaviour you observe is a missing SvGETMAGIC(sv) to handle such scalars.

use strict; use warnings; use List::Util qw( max ); use Variable::Magic qw( cast wizard ); # Make $x a magical variable that always returns 5. cast(my($x), wizard( get => sub { ${ $_[0] } = 5 }, ) ); $x = 3; if ($ARGV[0]) { no warnings 'void'; 0+$x } print('max($x, 4)=', max($x, 4), "\n"); print('$x=', $x, "\n");
$ perl a.pl 0 max($x, 4)=4 $x=5 $ perl a.pl 1 max($x, 4)=5 $x=5

In reply to Re: Max of 23 and 27 is 23? by ikegami
in thread Max of 23 and 27 is 23? by luxgladius

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.