develooper Front page | perl.perl5.porters | Postings from March 2003

Re: [perl #21411] [fix] Postponed RE with split()

Thread Previous | Thread Next
From:
Enache Adrian
Date:
March 2, 2003 00:09
Subject:
Re: [perl #21411] [fix] Postponed RE with split()
Message ID:
20030302081127.GA10782@ratsnest.hole
On Sat, Mar 01, 2003 at 12:16:51AM -0000, Philippe 'BooK' Bruhat (via RT) wrote:
> I wanted to try the experimental (??{ }) regexp construct in a split:
> 
> #!/usr/bin/perl
> #use re 'debug';
> my $i; sub n { ++$i }
> my $c = 'a';
> my $s = join '', map { $c++ x $_ } 1 .. shift;
> print join "|", split /((??{"."x n()}))/, $s;
...
> $ perl split_with_postponed_re 3
> |a||...||ccc
> Expected: |a||bb||ccc

Simpler example:
$ perl -le 'print join "|", split /((??{$i++}))/,"-1-3-5-"'

This should print '-|1|-|3|-|5|-' not '-|1|-|7|-|5|-'

The expression inside (??{ ... }) corrupts the stack.

Regards

Adi

Test for t/op/pat.t:
---------------------------------------------------------------
{
    my $i;
    ok('-1-3-5-' eq join('', split /((??{$i++}))/, '-1-3-5-'),
	"[perl #21411] (??{ .. }) corrupts split's stack")
}
---------------------------------------------------------------

Patch:
---------------------------------------------------------------
--- /arc/perl-current/pp.c	2003-02-25 16:35:04.000000000 +0200
+++ pp.c	2003-03-02 09:47:57.000000000 +0200
@@ -4632,6 +4632,7 @@ PP(pp_split)
 		}
 	    }
 	    s = rx->endp[0] + orig;
+	    PUTBACK;
 	}
     }
 

Thread Previous | Thread Next


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