scalar context, because pp_mapwhile and pp_grepwhile were using
their target as a temporary slot to store the return value.
p4raw-id: //depot/perl@22289
(void)POPMARK; /* pop dst */
SP = PL_stack_base + POPMARK; /* pop original mark */
if (gimme == G_SCALAR) {
- dTARGET;
- XPUSHi(items);
+ if (PL_op->op_private & OPpGREP_LEX) {
+ SV* sv = sv_newmortal();
+ sv_setiv(sv, items);
+ PUSHs(sv);
+ }
+ else {
+ dTARGET;
+ XPUSHi(items);
+ }
}
else if (gimme == G_ARRAY)
SP += items;
(void)POPMARK; /* pop dst */
SP = PL_stack_base + POPMARK; /* pop original mark */
if (gimme == G_SCALAR) {
- dTARGET;
- XPUSHi(items);
+ if (PL_op->op_private & OPpGREP_LEX) {
+ SV* sv = sv_newmortal();
+ sv_setiv(sv, items);
+ PUSHs(sv);
+ }
+ else {
+ dTARGET;
+ XPUSHi(items);
+ }
}
else if (gimme == G_ARRAY)
SP += items;
@INC = '../lib';
}
-print "1..64\n";
+print "1..66\n";
my $test = 0;
sub ok ($$) {
ok( $x eq '1globallocal-2globallocal', 'map without {}' );
}
{
+ for my $_ (1) {
+ my $x = map $_, qw(a b);
+ ok( $x == 2, 'map in scalar context' );
+ }
+}
+{
my $buf = '';
sub tgrep1 { /(.)/; $buf .= $1 }
my $_ = 'y';
ok( $_ eq 'local', '...but without extraneous side-effects' );
}
{
+ for my $_ (1) {
+ my $x = grep $_, qw(a b);
+ ok( $x == 2, 'grep in scalar context' );
+ }
+}
+{
my $s = "toto";
my $_ = "titi";
$s =~ /to(?{ ok( $_ eq 'toto', 'my $_ in code-match # TODO' ) })to/