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.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|