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.
|