In perl.git, the branch book/perlsecret has been updated

<http://perl5.git.perl.org/perl.git/commitdiff/2eec87731b3936785573fd8b5e8f72845f988ad0?hp=258767a1f7b22cca209166221a9db14306e8a44f>

- Log -----------------------------------------------------------------
commit 2eec87731b3936785573fd8b5e8f72845f988ad0
Author: Philippe Bruhat (BooK) <[email protected]>
Date:   Sun May 13 17:24:43 2012 +0200

    test both fixes for goatse split

M       t/japh/secret.t

commit 04d384780b784f91ebdb8114cb6d47ebc0b9ab14
Author: Aristotle Pagaltzis <[email protected]>
Date:   Sat May 12 09:25:01 2012 +0200

    add alternative for fixing goatse split

M       pod/perlsecret.pod
-----------------------------------------------------------------------

Summary of changes:
 pod/perlsecret.pod |   12 ++++++++++--
 t/japh/secret.t    |    6 ++++++
 2 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/pod/perlsecret.pod b/pod/perlsecret.pod
index 54722e8..adb6a4c 100644
--- a/pod/perlsecret.pod
+++ b/pod/perlsecret.pod
@@ -413,11 +413,19 @@ about the results, so C<split()> will B<not split the 
string at all>,
 and thus return the full string, which gives a list of only one element
 in scalar context, hence the C<1>.
 
-In this case, the proper secret operator to use is I<baby cart>:
+You have two options to address this. First, you can override C<split()>'s
+optimization by explicitly asking it to split into an unlimited number of
+fields:
+
+    my $count =()= split /:/, $string, -1;
+
+Or else you can defeat the optimization by using another secret operator
+instead, the I<baby cart>:
 
     my $count = @{[ split /:/, $string ]};
 
-which forces C<split()> to actually do the work, before the anonymous
+This causes C<split()> to detect that its caller can store any number of
+fields, thus it will actually do the work before the anonymous
 array is thrown away after being used in scalar context.
 
 
diff --git a/t/japh/secret.t b/t/japh/secret.t
index c71e566..a4cf405 100644
--- a/t/japh/secret.t
+++ b/t/japh/secret.t
@@ -129,6 +129,12 @@ $n =(@got)= "abababab" =~ /a/g;
 is( $n, 4, '=()=' );
 is( "@got", 'a a a a', '=()=' );
 
+# goatse + split
+$n =()= @{[ split /:/, "a:a:a:a" ]};
+is( $n, 4, "=()= split" );
+$n =()= split /:/, "a:a:a:a", -1;
+is( $n, 4, "=()= split" );
+
 # flaming xwing
 @got =<DATA>=~ /(\d+) is (\w+)/;
 is( "@got", '31337 eleet', '=<>=~' );

--
Perl5 Master Repository

Reply via email to