In perl.git, the branch blead has been updated <http://perl5.git.perl.org/perl.git/commitdiff/e4e95921cd0fd085a5edf35ae358cd213529e55a?hp=abdcbdb837d9244b83dc32ee471b3b7f383a6c18>
- Log ----------------------------------------------------------------- commit e4e95921cd0fd085a5edf35ae358cd213529e55a Author: Father Chrysostomos <[email protected]> Date: Sun Oct 26 17:01:07 2014 -0700 [perl #123057] Allow split-to-array in lvalue context In some cases @a=split gets optimised to something akin to split(\@a, ...) or split(..., \@a), so lvalue context applied to it sees a split op instead of a list assignment. And split canât be assigned to. So (@a=split//,"foo")=bar() fails. This bug probably goes back to perl 3, when this optimisation was added. (Actually, the array is usually stowed away in the pushre op that holds the regular expression, though sometimes it becomes the last argument.) Recent commits such as ef7999f have extended this optimisation, so it happens in more places, and ended up breaking chomp(my @array = split...). This commits checks specifically for split-to-array when lvalue con- text is applied. M op.c M t/op/chop.t M t/op/split.t commit 6c7f10b59397fa5a696d553f50ae0abc2bce312c Author: James E Keenan <[email protected]> Date: Sun Oct 26 10:14:40 2014 -0400 Test file fails to compile. For: RT #123057 M t/op/chop.t ----------------------------------------------------------------------- Summary of changes: op.c | 17 +++++++++++++++++ t/op/chop.t | 13 ++++++++++++- t/op/split.t | 5 ++++- 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/op.c b/op.c index fece8dd..59a3541 100644 --- a/op.c +++ b/op.c @@ -2844,6 +2844,23 @@ Perl_op_lvalue_flags(pTHX_ OP *o, I32 type, U32 flags) op_null(cUNOPx(cUNOPo->op_first)->op_first); /* pushmark */ op_null(o); return o; + + case OP_SPLIT: + kid = cLISTOPo->op_first; + if (kid && kid->op_type == OP_PUSHRE && + ( kid->op_targ + || o->op_flags & OPf_STACKED +#ifdef USE_ITHREADS + || ((PMOP*)kid)->op_pmreplrootu.op_pmtargetoff +#else + || ((PMOP*)kid)->op_pmreplrootu.op_pmtargetgv +#endif + )) { + /* This is actually @array = split. */ + PL_modcount = RETURN_UNLIMITED_NUMBER; + break; + } + goto nomod; } /* [20011101.069] File test operators interpret OPf_REF to mean that diff --git a/t/op/chop.t b/t/op/chop.t index 3cf8735..f1267ad 100644 --- a/t/op/chop.t +++ b/t/op/chop.t @@ -6,7 +6,7 @@ BEGIN { require './test.pl'; require './charset_tools.pl'; } -plan tests => 143; +plan tests => 144; $_ = 'abc'; $c = foo(); @@ -263,3 +263,14 @@ foreach my $start (@chars) { is($result, "\x{fffffffffffffffe}", "chop even higher 'unicode' - result"); } } + +$/ = "\n"; +{ + my $expected = 99999; + my $input = "UserID\talpha $expected\n"; + my $uid = ''; + chomp(my @line = split (/ |\t/,$input)); + $uid = $line[-1]; + is($uid, $expected, + "RT #123057: chomp works as expected on split"); +} diff --git a/t/op/split.t b/t/op/split.t index 88956c7..51e0d1d 100644 --- a/t/op/split.t +++ b/t/op/split.t @@ -6,7 +6,7 @@ BEGIN { set_up_inc('../lib'); } -plan tests => 122; +plan tests => 123; $FS = ':'; @@ -505,3 +505,6 @@ is "@aaa", "f o o b a r b a z", () = @a = split //, "abc"; is "@a", "a b c", '() = split-to-array'; + +(@a = split //, "abc") = 1..10; +is "@a", '1 2 3', 'assignment to split-to-array'; -- Perl5 Master Repository
