develooper Front page | perl.perl5.porters | Postings from June 2001

Bug report: split splits on wrong pattern

Thread Next
From:
Marcel Grunauer
Date:
June 27, 2001 04:33
Subject:
Bug report: split splits on wrong pattern
Message ID:
20010627113312.RWGY6087.viemta06@localhost
Sorry for not sending this via perlbug, but none of my perlbug
reports seem to have made it to the list. Is it possible I've been
added to a list of spammers because I had some trouble with mail
configuration and sent mails with empty subjects? Anyway...


This is a bug report for perl from marcel@codewerk.com,
generated with the help of perlbug 1.28 running under perl v5.6.0.

I've spent the last hour trying to find out why the third call to
mysplit() in the program below produces the wrong result, but the
first one produces the correct one. It seems once you call mysplit()
with the default pattern of /\s+/, this pattern is used all the
time from then on.

It's about splitting the string 'hello cruel world' along /ll/;
the first call is ok (produces 'he:o cruel world'), but the third
one is not, using the wrong pattern (/\s+/) to produce 
'hello:cruel:world'.

BTW, the value of $limit doesn't seem to matter. '0' is as good as
'9' in this case.

This is both on 5.6.0 and perl@10907 on darwin. Philip Newton also
verified those results. Also below is the output when running with
the debugger. Note that the manual print statement on the debugger
command line produces the correct result on the third call to
mysplit(), but when actually executed produces the wrong result.

Marcel

---------------8<---------------
#!/usr/bin/perl

use warnings;
use strict;

sub mysplit {
         my ($orig, $pat, $limit) = @_;
         $pat = qr/\s+/ unless ref($pat) eq 'Regexp';
         $limit ||= 0;
         print "orig  = <$orig>\n";
         print "pat   = <$pat>\n";
         print "limit = <$limit>\n";
         $DB::single = 1;
         print join ':' => split($pat, $orig, $limit);
         print "\n\n";
}

my $t = 'hello cruel world';
mysplit($t, qr/ll/);
mysplit($t);
mysplit($t, qr/ll/);
---------------8<---------------

Output:

---------------8<---------------
orig  = <hello cruel world>
pat   = <(?-xism:ll)>
limit = <0>
he:o cruel world

orig  = <hello cruel world>
pat   = <(?-xism:\s+)>
limit = <0>
hello:cruel:world

orig  = <hello cruel world>
pat   = <(?-xism:ll)>
limit = <0>
hello:cruel:world
---------------8<---------------

Output of the debugger run:

---------------8<---------------
[marcelgr@localhost tmp]$ perl -d split.pl
Default die handler restored.

Loading DB routines from perl5db.pl version 1.07
Editor support available.

Enter h or `h h' for help, or `man perldebug' for more help.

main::(split.pl:18):    my $t = 'hello cruel world';
   DB<1> c
orig  = <hello cruel world>
pat   = <(?-xism:ll)>
limit = <0>
main::mysplit(split.pl:14):             print join ':' => split($pat, 
$orig, $limit);
   DB<1> c
he:o cruel world

orig  = <hello cruel world>
pat   = <(?-xism:\s+)>
limit = <0>
main::mysplit(split.pl:14):             print join ':' => split($pat, 
$orig, $limit);
   DB<1> c
hello:cruel:world

orig  = <hello cruel world>
pat   = <(?-xism:ll)>
limit = <0>
main::mysplit(split.pl:14):             print join ':' => split($pat, 
$orig, $limit);
   DB<1> print join ':' => split($pat, $orig, $limit);
he:o cruel world
   DB<2> s
hello:cruel:worldmain::mysplit(split.pl:15):             print "\n\n";
   DB<2> r

void context return from main::mysplit
Debugged program terminated.  Use q to quit or R to restart,
   use O inhibit_exit to avoid stopping after program termination,
   h q, h R or h O to get additional info.
---------------8<---------------
---
Flags:
     category=core
     severity=high
---
Site configuration information for perl v5.6.0:

Configured by root at Fri Feb 16 16:58:39 PST 2001.

Summary of my perl5 (revision 5.0 version 6 subversion 0) configuration:
   Platform:
     osname=darwin, osvers=1.0, archname=darwin
     uname='darwin negative 1.0 darwin kernel version 1.3: wed jan 3 
16:05:51 pst
  2001; aramesh:buildobjrelease_ppc power macintosh powerpc '
     config_args='-ds -e -Dprefix=/usr -Dccflags=-g  -pipe  -Dldflags='
     hint=recommended, useposix=true, d_sigaction=define
     usethreads=undef use5005threads=undef useithreads=undef 
usemultiplicity=unde
f
     useperlio=undef d_sfio=undef uselargefiles=define
     use64bitint=undef use64bitall=undef uselongdouble=undef 
usesocks=undef
   Compiler:
     cc='cc', optimize='-O3', gccversion=Apple DevKit-based CPP 6.0alpha
     cppflags='-g -pipe -pipe -fno-common -DHAS_TELLDIR_PROTOTYPE 
-fno-strict-ali
asing'
     ccflags ='-g -pipe -pipe -fno-common -DHAS_TELLDIR_PROTOTYPE 
-fno-strict-ali
asing'
     stdchar='char', d_stdstdio=undef, usevfork=true
     intsize=4, longsize=4, ptrsize=4, doublesize=8
     d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=8
     ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', 
lseeksize
=8
     alignbytes=8, usemymalloc=n, prototype=define
   Linker and Libraries:
     ld='cc', ldflags =''
     libpth=/usr/lib
     libs=-lm -lc
     libc=/System/Library/Frameworks/System.framework/System, so=dylib, 
useshrpli
b=true, libperl=libperl.dylib
   Dynamic Linking:
     dlsrc=dl_dyld.xs, dlext=bundle, d_dlsymun=undef, ccdlflags=' '
     cccdlflags=' ', lddlflags='-bundle -undefined suppress'

Locally applied patches:


---
@INC for perl v5.6.0:
     /Users/marcelgr/lib/perl
     /Users/marcelgr/www/lib/perl
     /System/Library/Perl/darwin
     /System/Library/Perl
     /Library/Perl/darwin
     /Library/Perl
     /Library/Perl
     /Network/Library/Perl/darwin
     /Network/Library/Perl
     /Network/Library/Perl
     .

---
Environment for perl v5.6.0:
     DYLD_LIBRARY_PATH (unset)
     HOME=/Users/marcelgr
     LANG=en_US
     LANGUAGE (unset)
     LC_ALL=C
     LD_LIBRARY_PATH (unset)
     LOGDIR (unset)
     
PATH=/Users/marcelgr/bin:/usr/local/bin:/usr/local/pgsql/bin:/usr/bin:/bin:
/
usr/local/sbin:/usr/sbin:/sbin
     PERL5LIB=/Users/marcelgr/lib/perl:/Users/marcelgr/www/lib/perl
     PERL_BADLANG (unset)
     SHELL=/usr/bin/bash

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