17 ($a,$b,$c) = split($FS,$_);
19 is(join(';',$a,$b,$c), 'a;b;c');
22 is(join("$_",@ary), 'aa:b:cc');
25 my @xyz = (@ary = split(//));
26 is(join(".",@ary), "a.b.c.\n");
30 is(join(".",@ary), "a.b.c");
32 $_ = join(':',split(' '," a b\tc \t d "));
35 $_ = join(':',split(/ */,"foo bar bie\tdoll"));
36 is($_ , "f:o:o:b:a:r:b:i:e:\t:d:o:l:l");
38 $_ = join(':', 'foo', split(/ /,'a b c'), 'bar');
39 is($_, "foo:a:b::c:bar");
41 # Can we say how many fields to split to?
42 $_ = join(':', split(' ','1 2 3 4 5 6', 3));
43 is($_, '1:2:3 4 5 6');
45 # Can we do it as a variable?
47 $_ = join(':', split(' ','1 2 3 4 5 6', $x));
48 is($_, '1:2:3:4 5 6');
50 # Does the 999 suppress null field chopping?
51 $_ = join(':', split(/:/,'1:2:3:4:5:6:::', 999));
52 is($_ , '1:2:3:4:5:6:::');
54 # Does assignment to a list imply split to one more field than that?
56 if ($Config{useithreads}) {
57 skip("No IV value dump with threads", 1);
60 $foo = runperl( switches => ['-Dt'], stderr => 1, prog => '($a,$b)=split;' );
61 ok($foo =~ /DEBUGGING/ || $foo =~ /const\n?\Q(IV(3))\E/);
65 # Can we say how many fields to split to when assigning to a list?
66 ($a,$b) = split(' ','1 2 3 4 5 6', 2);
68 is($_, '1:2 3 4 5 6');
70 # do subpatterns generate additional fields (without trailing nulls)?
71 $_ = join '|', split(/,|(-)/, "1-10,20,,,");
74 # do subpatterns generate additional fields (with a limit)?
75 $_ = join '|', split(/,|(-)/, "1-10,20,,,", 10);
76 is($_, "1|-|10||20||||||");
78 # is the 'two undefs' bug fixed?
79 (undef, $a, undef, $b) = qw(1 2 3 4);
84 local(undef, $a, undef, $b) = qw(1 2 3 4);
88 # check splitting of null string
89 $_ = join('|', split(/x/, '',-1), 'Z');
92 $_ = join('|', split(/x/, '', 1), 'Z');
95 $_ = join('|', split(/(p+)/,'',-1), 'Z');
98 $_ = join('|', split(/.?/, '',-1), 'Z');
102 # Are /^/m patterns scanned?
103 $_ = join '|', split(/^a/m, "a b a\na d a", 20);
104 is($_, "| b a\n| d a");
106 # Are /$/m patterns scanned?
107 $_ = join '|', split(/a$/m, "a b a\na d a", 20);
108 is($_, "a b |\na d |");
110 # Are /^/m patterns scanned?
111 $_ = join '|', split(/^aa/m, "aa b aa\naa d aa", 20);
112 is($_, "| b aa\n| d aa");
114 # Are /$/m patterns scanned?
115 $_ = join '|', split(/aa$/m, "aa b aa\naa d aa", 20);
116 is($_, "aa b |\naa d |");
120 @ary = split(/\s*:\s*/);
121 is(($res = join(".",@ary)), "a.b.c.d", $res);
123 # use of match result as pattern (!)
124 is('p:q:r:s', join ':', split('abc' =~ /b/, 'p1q1r1s'));
126 # /^/ treated as /^/m
127 $_ = join ':', split /^/, "ab\ncd\nef\n";
128 is($_, "ab\n:cd\n:ef\n");
130 # see if @a = @b = split(...) optimization works
131 @list1 = @list2 = split ('p',"a p b c p");
132 ok(@list1 == @list2 &&
133 "@list1" eq "@list2" &&
135 "@list1" eq "a b c ");
137 # zero-width assertion
138 $_ = join ':', split /(?=\w)/, "rm b";
143 @ary = map {ord} split //, v1.20.300.4000.50000.4000.300.20.1;
144 is("@ary", "1 20 300 4000 50000 4000 300 20 1");
146 @ary = split(/\x{FE}/, "\x{FF}\x{FE}\x{FD}"); # bug id 20010105.016
148 $ary[0] eq "\xFF" && $ary[1] eq "\xFD" &&
149 $ary[0] eq "\x{FF}" && $ary[1] eq "\x{FD}");
151 @ary = split(/(\x{FE}\xFE)/, "\xFF\x{FF}\xFE\x{FE}\xFD\x{FD}"); # variant of 31
153 $ary[0] eq "\xFF\xFF" &&
154 $ary[0] eq "\x{FF}\xFF" &&
155 $ary[0] eq "\x{FF}\x{FF}" &&
156 $ary[1] eq "\xFE\xFE" &&
157 $ary[1] eq "\x{FE}\xFE" &&
158 $ary[1] eq "\x{FE}\x{FE}" &&
159 $ary[2] eq "\xFD\xFD" &&
160 $ary[2] eq "\x{FD}\xFD" &&
161 $ary[2] eq "\x{FD}\x{FD}");
164 my @a = map ord, split(//, join("", map chr, (1234, 123, 2345)));
165 is("@a", "1234 123 2345");
170 my @a = map ord, split(/$x/, join("", map chr, (1234, ord($x), 2345)));
171 is("@a", "1234 2345");
175 # bug id 20000427.003
180 my $sushi = "\x{b36c}\x{5a8c}\x{ff5b}\x{5079}\x{505b}";
182 my @charlist = split //, $sushi;
184 foreach my $ch (@charlist) {
185 $r = $r . " " . sprintf "U+%04X", ord($ch);
188 is($r, " U+B36C U+5A8C U+FF5B U+5079 U+505B");
192 my $s = "\x20\x40\x{80}\x{100}\x{80}\x40\x20";
195 if (ord('A') == 193) {
198 # bug id 20000426.003
200 my ($a, $b, $c) = split(/\x40/, $s);
201 ok($a eq "\x20" && $b eq "\x{80}\x{100}\x{80}" && $c eq $a);
205 my ($a, $b) = split(/\x{100}/, $s);
206 ok($a eq "\x20\x40\x{80}" && $b eq "\x{80}\x40\x20");
208 my ($a, $b) = split(/\x{80}\x{100}\x{80}/, $s);
209 ok($a eq "\x20\x40" && $b eq "\x40\x20");
212 if (ord('A') == 193) {
215 my ($a, $b) = split(/\x40\x{80}/, $s);
216 ok($a eq "\x20" && $b eq "\x{100}\x{80}\x40\x20");
220 my ($a, $b, $c) = split(/[\x40\x{80}]+/, $s);
221 ok($a eq "\x20" && $b eq "\x{100}" && $c eq "\x20");
227 my $a = "ABC\x{263A}";
229 my @b = split( //, $a );
233 ok(length($b[3]) == 1 && $b[3] eq "\x{263A}");
236 ok(length($a) == 4 && $a eq "ZBC\x{263A}");
240 my @a = split(/\xFE/, "\xFF\xFE\xFD");
242 ok(@a == 2 && $a[0] eq "\xFF" && $a[1] eq "\xFD");
246 # check that PMf_WHITE is cleared after \s+ is used
247 # reported in <20010627113312.RWGY6087.viemta06@localhost>
249 foreach my $pat ( qr/\s+/, qr/ll/ ) {
250 $r = join ':' => split($pat, "hello cruel world");
252 is($r, "he:o cruel world");
257 # split /(A)|B/, "1B2" should return (1, undef, 2)
258 my @x = split /(A)|B/, "1B2";
259 ok($x[0] eq '1' and (not defined $x[1]) and $x[2] eq '2');
265 local $SIG{__WARN__} = sub { $warn = join '', @_; chomp $warn };
266 my $char = "\x{10f1ff}";
267 my @a = split /\r?\n/, "$char\n";
268 ok(@a == 1 && $a[0] eq $char && !defined($warn));
275 $_ = 'readin,database,readout';
276 utf8::upgrade $_ if $u;
278 my @d = split /[,]/,$1;
279 is(join (':',@d), 'readin:database:readout', "[perl #18195]");
287 eval { @a=split(/[, ]+/,$p) };
288 is ("$@-@a-", '-a b-', '#20912 - split() to array with /[]+/ and utf8');
292 is (\@a, \@{"a"}, '@a must be global for following test');
294 $n = @a = split /,/,$p;
295 is ($n, 0, '#21765 - pmreplroot hack used to return undef for 0 iters');
300 # assigning off the end of the array after a split could leave garbage
301 # in the inner elements
304 @a = split /,/, ',,,,,';
307 is (ref $x, 'SCALAR', '#28938 - garbage after extend');
310 # check the special casing of split /\s/ and unicode
311 use charnames qw(:full);
312 # below test data is extracted from
314 # Date: 2006-06-07, 23:22:52 GMT [MD]
316 # Unicode Character Database
317 # Copyright (c) 1991-2006 Unicode, Inc.
318 # For terms of use, see http://www.unicode.org/terms_of_use.html
319 # For documentation, see UCD.html
321 ord("\t"), # Cc <control-0009>
322 ord("\n"), # Cc <control-000A>
323 # not PerlSpace # Cc <control-000B>
324 ord("\f"), # Cc <control-000C>
325 ord("\r"), # Cc <control-000D>
327 ord("\N{NEL}"), # Cc <control-0085>
328 ord("\N{NO-BREAK SPACE}"),
330 0x1680, # Zs OGHAM SPACE MARK
331 0x180E, # Zs MONGOLIAN VOWEL SEPARATOR
332 0x2000..0x200A, # Zs [11] EN QUAD..HAIR SPACE
333 0x2028, # Zl LINE SEPARATOR
334 0x2029, # Zp PARAGRAPH SEPARATOR
335 0x202F, # Zs NARROW NO-BREAK SPACE
336 0x205F, # Zs MEDIUM MATHEMATICAL SPACE
337 0x3000 # Zs IDEOGRAPHIC SPACE
339 #diag "Have @{[0+@spaces]} to test\n";
340 foreach my $cp (@spaces) {
341 my $msg = sprintf "Space: U+%04x", $cp;
342 my $space = chr($cp);
343 my $str="A:$space:B\x{FFFD}";
346 my @res=split(/\s+/,$str);
347 ok(@res == 2 && join('-',@res) eq "A:-:B", "$msg - /\\s+/");
349 my $s2 = "$space$space:A:$space$space:B\x{FFFD}";
352 my @r2 = split(' ',$s2);
353 ok(@r2 == 2 && join('-', @r2) eq ":A:-:B", "$msg - ' '");
355 my @r3 = split(/\s+/, $s2);
356 ok(@r3 == 3 && join('-', @r3) eq "-:A:-:B", "$msg - /\\s+/ No.2");
361 my $src = "ABC \0 FOO \0 XYZ";
362 my @s = split(" \0 ", $src);
363 my @r = split(/ \0 /, $src);
368 is(join(':',@s), join(':',@r));