in reply to Re-reading history from 2001 / using a capture during split

split is splitting on the un-captured 'B', and since it's not captured...

No, it's the (A) that's not captured. Every group produces a field, as last paragraph in split explains.

If the PATTERN contains capturing groups, then for each separator, an additional field is produced for each substring captured by a group (in the order in which the groups are specified, as per backreferences); if any group does not match, then it captures the undef value instead of a substring
DB<3> @foo = split /(A)|(B)/, "1A2B3" DB<4> x @foo 0 1 1 'A' 2 undef 3 2 4 undef 5 'B' 6 3

I'm reading linked node as japhy apologizes for what he did (i.e. making "split" to return empty string), and acknowledges that returning "undef" was correct from the very begining.

Replies are listed 'Best First'.
Re^2: Re-reading history from 2001
by choroba (Cardinal) on Mar 05, 2019 at 17:14 UTC
    Yes, and to get rid of the undefs, one can use the branch reset pattern:
    my @foo = split /(?|(A)|(B))/, "1A2B3"; use Data::Dumper; print Dumper \@foo;
    $VAR1 = [ '1', 'A', '2', 'B', '3' ];
    map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]