As mentioned in ticket #24346, scalar() should not change lvalueness.
The fact that it did was a side effect of the implementation and a
bug. foo(scalar substr(....)) should pass a substr lvalue to foo just
as it would without scalar() or with a $ prototype (which is meant to
be equivalent to scalar()).
This also makes it possible to force scalar context in list assignment
to lvalue subroutines, as in (foo(), scalar bar()) = @list.
else if (!(o->op_flags & OPf_KIDS))
break;
if (o->op_targ != OP_LIST) {
+ case OP_SCALAR:
op_lvalue(cBINOPo->op_first, type);
break;
}
BEGIN { require './test.pl'; }
-plan(381);
+plan(382);
run_tests() unless caller;
}
}
+# Also part of perl #24346; scalar(substr...) should not affect lvalueness
+{
+ my $str = "abcdef";
+ sub { $_[0] = 'dea' }->( scalar substr $str, 3, 2 );
+ is $str, 'abcdeaf', 'scalar does not affect lvalueness of substr';
+}
+
# [perl #24200] string corruption with lvalue sub
{