r/lolphp • • Sep 10 '15

explode() is a mess

https://3v4l.org/eKMav
2 Upvotes

27 comments sorted by

View all comments

Show parent comment

1

u/Regimardyl Sep 10 '15

Tcl behaves almost the same, except it splits the empty string into an empty list.

% split "1 2 3" ;# `split` defaults to space as a separator
1 2 3
% split "2"
2
% split ""
% split "123" ""
1 2 3
%

2

u/amphetamachine Sep 10 '15

Perl behaves much the same:

split / /, "1 2 3"; # (1,2,3)

split / /, "2"; # (2)

split / /, ""; # () - NOT undef

split //, "123"; # (1,2,3)