Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passing qr/\s+/ into a subroutine as a delimiter for split seems to cause a subsequent call to that function to fail in v5.6.1 #7391

Closed
p5pRT opened this issue Jun 28, 2004 · 4 comments

Comments

@p5pRT
Copy link

p5pRT commented Jun 28, 2004

Migrated from rt.perl.org#30505 (status was 'resolved')

Searchable as RT30505$

@p5pRT
Copy link
Author

p5pRT commented Jun 28, 2004

From joseph.reel@citigroup.com

In Perl 5.6.1 the following script

#!/opt/mr/perl/bin/perl -w
use strict;

my @​c = test ("dealloans dat", qr/\s{1,256}/);
my @​d = test ("dealloans|dat", qr/\|/);
print "@​c\n";
print "@​d\n";

sub test {
  my ($data, $delim) = @​_;
  my @​d = split /$delim/, $data;
  return @​d;
}

results in output

dealloans dat
dealloans dat

as expected, but replacing qr/\s{1,256}/ above with qr/\s+/ gives output

dealloans dat
dealloans|dat

so it looks like the second subroutine call fails.

@p5pRT
Copy link
Author

p5pRT commented Jun 29, 2004

From @hvds

"Reel, Joseph \[FI\]" (via RT) <perlbug-followup@​perl.org> wrote​:
:In Perl 5.6.1 the following script
:
:#!/opt/mr/perl/bin/perl -w
:use strict;
:
:my @​c = test ("dealloans dat", qr/\s{1,256}/);
:my @​d = test ("dealloans|dat", qr/\|/);
:print "@​c\n";
:print "@​d\n";
:
:sub test {
: my ($data, $delim) = @​_;
: my @​d = split /$delim/, $data;
: return @​d;
:}
:
:results in output
:
:dealloans dat
:dealloans dat
:
:as expected, but replacing qr/\s{1,256}/ above with qr/\s+/ gives output
:
:dealloans dat
:dealloans|dat
:
:so it looks like the second subroutine call fails.

Thanks for the report. This bug has been fixed in perl-5.8.0 and later
releases.

I suspect that in 5.6.1 there may be a specific optimisation for
split(/\s+/, ...) implemented by modifying the compiled split() node
itself, but failing to ensure that the optimisation was applied only
when the pattern was supplied as a constant.

If you need a specific workaround for 5.6.1, it looks as if you can
defeat the optimisation by including something extra when you incorporate
the supplied pattern, eg​:
  my @​d = split /$delim(?=)/, $data;
.. but this will defeat many optimisations, and may therefore have a
noticeable runtime cost.

Hugo

@p5pRT
Copy link
Author

p5pRT commented Jun 29, 2004

The RT System itself - Status changed from 'new' to 'open'

@p5pRT
Copy link
Author

p5pRT commented May 31, 2008

p5p@spam.wizbit.be - Status changed from 'open' to 'resolved'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant