in reply to Re: qr bug in perl 5.6.1 with lexicals
in thread qr bug in perl 5.6.1 with lexicals

The problem is that split() chokes when you supply a regexp with //o or compilier with qr.
  • Comment on Re^2: qr bug in perl 5.6.1 with lexicals

Replies are listed 'Best First'.
Re^3: qr bug in perl 5.6.1 with lexicals
by ikegami (Patriarch) on Dec 16, 2008 at 23:54 UTC

    Not so.

    >c:\progs\perl561\bin\perl -le"$x=qr/,/; print for split $x, 'a,b,c'" a b c

    Still not enough information. Don't make us guess, show us some code!

      use warnings; use strict; my @OuterData = ( "This is some space separated text", "On three different lines", "So you can see what happens"); my @InnerData = ( "1, 2, 3, 4", "2, 6, 7, 8", "3, 10, 11, 12", "4, 17, 22, 21", "5, B, C, E, F", "6, 2, 3, 4, 5"); FileParse('\s+', \@OuterData, sub { my @Words = @_; my $NWords = scalar @Words; print "Line has $NWords words. '@Words'\n"; FileParse(',\s*', \@InnerData, sub { my ($Key, @Values) = @_; $Key == $NWords and print join(' ',@Values)," - "; }); print join("-",@Words),"\n"; }); sub FileParse { my ($PatternCore, $TextAref, $Code) = @_; # print "$PatternCore, $TextAref, $Code\n"; my $regexp_p = qr/$PatternCore/; foreach my $line (@{$TextAref}) { # my @Data = split($PatternCore, $line); my @Data = split($regexp_p, $line); $Code->(@Data); } } =cut Perl 5.6.1 built for sun4-solaris Line has 6 words. 'This is some space separated text' Argument "1," isn't numeric in numeric eq (==) at pbug.pl line 30. Argument "2," isn't numeric in numeric eq (==) at pbug.pl line 30. Argument "3," isn't numeric in numeric eq (==) at pbug.pl line 30. Argument "4," isn't numeric in numeric eq (==) at pbug.pl line 30. Argument "5," isn't numeric in numeric eq (==) at pbug.pl line 30. Argument "6," isn't numeric in numeric eq (==) at pbug.pl line 30. 2, 3, 4, 5 - This-is-some-space-separated-text Line has 4 words. 'On three different lines' Argument "1," isn't numeric in numeric eq (==) at pbug.pl line 30. Argument "2," isn't numeric in numeric eq (==) at pbug.pl line 30. Argument "3," isn't numeric in numeric eq (==) at pbug.pl line 30. perl-5.8.8 Line has 6 words. 'This is some space separated text' 2 3 4 5 - This-is-some-space-separated-text Line has 4 words. 'On three different lines' 17 22 21 - On-three-different-lines Line has 6 words. 'So you can see what happens' 2 3 4 5 - So-you-can-see-what-happens And if you really want to have fun: Try changing my $Regexp_ref; To: our $Regexp_ref; Passing the string directly into split seems to work with perl 5.6.1 a +nd perl 5.8.8

        I can't reproduce your problem with ActivePerl 5.6.1 build 635, but I can reproduce it with ActivePerl 5.6.0 build 623

        >c:\progs\perl588\bin\perl 730963.pl Line has 6 words. 'This is some space separated text' 2 3 4 5 - This-is-some-space-separated-text Line has 4 words. 'On three different lines' 17 22 21 - On-three-different-lines Line has 6 words. 'So you can see what happens' 2 3 4 5 - So-you-can-see-what-happens >c:\progs\perl561\bin\perl 730963.pl Line has 6 words. 'This is some space separated text' 2 3 4 5 - This-is-some-space-separated-text Line has 4 words. 'On three different lines' 17 22 21 - On-three-different-lines Line has 6 words. 'So you can see what happens' 2 3 4 5 - So-you-can-see-what-happens >c:\progs\perl560\bin\perl 730963.pl Line has 6 words. 'This is some space separated text' Argument "1," isn't numeric in numeric eq (==) at !.pl line 25. Argument "2," isn't numeric in numeric eq (==) at !.pl line 25. Argument "3," isn't numeric in numeric eq (==) at !.pl line 25. Argument "4," isn't numeric in numeric eq (==) at !.pl line 25. Argument "5," isn't numeric in numeric eq (==) at !.pl line 25. Argument "6," isn't numeric in numeric eq (==) at !.pl line 25. 2, 3, 4, 5 - This-is-some-space-separated-text Line has 4 words. 'On three different lines' Argument "1," isn't numeric in numeric eq (==) at !.pl line 25. Argument "2," isn't numeric in numeric eq (==) at !.pl line 25. Argument "3," isn't numeric in numeric eq (==) at !.pl line 25. Argument "4," isn't numeric in numeric eq (==) at !.pl line 25. 17, 22, 21 - Argument "5," isn't numeric in numeric eq (==) at !.pl li +ne 25. Argument "6," isn't numeric in numeric eq (==) at !.pl line 25. On-three-different-lines Line has 6 words. 'So you can see what happens' Argument "1," isn't numeric in numeric eq (==) at !.pl line 25. Argument "2," isn't numeric in numeric eq (==) at !.pl line 25. Argument "3," isn't numeric in numeric eq (==) at !.pl line 25. Argument "4," isn't numeric in numeric eq (==) at !.pl line 25. Argument "5," isn't numeric in numeric eq (==) at !.pl line 25. Argument "6," isn't numeric in numeric eq (==) at !.pl line 25. 2, 3, 4, 5 - So-you-can-see-what-happens

        The only workaround I've found is to change
        my $regexp_p = qr/$PatternCore/;
        to
        my $regexp_p = $PatternCore;

        And if you really want to have fun:
        Try changing my $Regexp_ref;
        To: our $Regexp_ref;

        You mean $regexp_p? No change. my $regexp_p, our $regexp_p and local our $regexp_p all produced the same result.