develooper Front page | perl.perl5.porters | Postings from July 2000

[PATCH] split /^/

From:
M.J.T. Guy
Date:
July 25, 2000 06:19
Subject:
[PATCH] split /^/
Message ID:
E13H4bp-00062h-00@libra.cus.cam.ac.uk
This patch (for perl-current) documents and tests the special behaviour
of split /^/.

Mike Guy

--- ./pod/perlfunc.pod.orig	Sat Jul 15 01:56:01 2000
+++ ./pod/perlfunc.pod	Tue Jul 25 14:09:25 2000
@@ -4378,6 +4378,9 @@
 whitespace produces a null first field.  A C<split> with no arguments
 really does a C<split(' ', $_)> internally.
 
+A PATTERN of C</^/) is also a special case  -  it's treated as if
+it were C/^/m), since it isn't much use otherwise.
+
 Example:
 
     open(PASSWD, '/etc/passwd');
--- ./t/op/split.t.orig	Mon Jul 24 18:46:48 2000
+++ ./t/op/split.t	Tue Jul 25 14:13:23 2000
@@ -2,7 +2,7 @@
 
 # $RCSfile: split.t,v $$Revision: 4.1 $$Date: 92/08/07 18:28:26 $
 
-print "1..26\n";
+print "1..27\n";
 
 $FS = ':';
 
@@ -113,3 +113,8 @@
 # use of match result as pattern (!)
 'p:q:r:s' eq join ':', split('abc' =~ /b/, 'p1q1r1s') or print "no ";
 print "ok 26\n";
+
+# /^/ treated as /^/m
+$_ = join ':', split /^/, "ab\ncd\nef\n";
+print "not " if $_ != "ab\n:cd\n:ef";
+print "ok 27\n";

End of patch



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About