You're specifying a limit of 2. You can make 2 fields out of the string "bla=" splitting on = - the last field is the empty string following the = sign.

If you hadn't specified the limit, you would have got what you expected:

Splits the string EXPR into a list of strings and returns that list. By default, empty leading fields are preserved, and empty trailing ones are deleted. (If all fields are empty, they are considered to be trailing.)

...

If LIMIT is unspecified or zero, trailing null fields are stripped (which potential users of "pop" would do well to remember).

(from split, emphasis mine). Note that using a limit of 1 does not split the string (which was news to me):

#!/usr/bin/perl -w use strict; sub pr { print "'$_[0]' (no limit) => [".join(",",map { defined $_ ? "'$_'" + : 'undef' } split /=/,$_[0])."]\n" ; print "'$_[0]' (limit 1) => [".join(",",map { defined $_ ? "'$_'" +: 'undef' } split /=/,$_[0],1)."]\n" ; print "'$_[0]' (limit 2) => [".join(",",map { defined $_ ? "'$_'" +: 'undef' } split /=/,$_[0],2)."]\n" ; } pr(''); pr('a'); pr('='); pr('a='); pr('a=b');
update: output:
'' (no limit) => [] '' (limit 1) => [] '' (limit 2) => [] 'a' (no limit) => ['a'] 'a' (limit 1) => ['a'] 'a' (limit 2) => ['a'] '=' (no limit) => [] '=' (limit 1) => ['='] '=' (limit 2) => ['',''] 'a=' (no limit) => ['a'] 'a=' (limit 1) => ['a='] 'a=' (limit 2) => ['a',''] 'a=b' (no limit) => ['a','b'] 'a=b' (limit 1) => ['a=b'] 'a=b' (limit 2) => ['a','b']
updated again fixed code & output.

In reply to Re: undef vs empty string '' from split by Joost
in thread undef vs empty string '' from split by chrism01

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.