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

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

Thread Previous | Thread Next
From:
l . mai @ web . de
Date:
September 11, 2014 12:28
Subject:
[perl #122761] split /\A/ works like /^/m, matches embedded newlines
Message ID:
rt-4.0.18-26241-1410438517-1530.122761-75-0@perl.org
# New Ticket Created by  l.mai@web.de 
# Please include the string:  [perl #122761]
# in the subject line of all future correspondence about this issue. 
# <URL: https://rt.perl.org/Ticket/Display.html?id=122761 >


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"'
[foo
]
[bar
]
[baz]

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


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About