develooper Front page | perl.perl5.porters | Postings from January 2004

(?{ }) inside split() regex

Thread Next
From:
Jeff 'japhy' Pinyan
Date:
January 31, 2004 19:28
Subject:
(?{ }) inside split() regex
Message ID:
Pine.LNX.4.44.0401312224440.19191-100000@perlmonk.org
This program:

  @parts = split m{
    \s+(?(?{$x&1})(?!))
   |
    "(?{++$x})(?!)
  }x, q{A "B C" D"E F" G};

  print "<$_>\n" for @parts;

prints some weird values:

  <0>
  <1>
  <D"E F">
  <G>

I'd have expected:

  <A>
  <"B C">
  <D"E F">
  <G>

It looks like $x's value is getting used somewhere that it shouldn't be.
I'm using 5.8.0; could someone verify this in more recent versions?

-- 
Jeff "japhy" Pinyan      japhy@pobox.com      http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
<stu> what does y/// stand for?  <tenderpuss> why, yansliterate of course.
[  I'm looking for programming work.  If you like my work, let me know.  ]



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