develooper Front page | perl.perl5.porters | Postings from September 2014

[perl #122761] split /\A/ works like /^/m, matches embedded newlines

Thread Previous | Thread Next
l . mai @ web . de
September 11, 2014 12:28
[perl #122761] split /\A/ works like /^/m, matches embedded newlines
Message ID:
# New Ticket Created by 
# Please include the string:  [perl #122761]
# in the subject line of all future correspondence about this issue. 
# <URL: >

perldoc perlrebackslash:

   \A  "\A" only matches at the beginning of the string.

perldoc -f split:

   Empty leading fields are produced when there are positive-width matches at the beginning of the string; a zero-width match at the beginning of the string does not produce an empty field.

Therefore split /\A/ should return the input string as is. \A can only match once (at offset 0), which (logically speaking) should turn "foo" into ("", "foo"), but because of the special case in split of not producing empty leading fields for zero-width matches at the beginning, we just get "foo" again.

What actually happens:

$ perl -wE 'say "[$_]" for split /\A/, "foo\nbar\nbaz"'

Apparently split thinks /\A/ is the same as /^/m, matching after every embedded newline in the input string. I think this is a bug in split.

The test above was with:
This is perl 5, version 12, subversion 4 (v5.12.4) built for x86_64-linux

... but an IRC bot running 5.20.0 produces the same results so I assume it's still present in 5.20.

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About