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

$s = ""; $n = @a = split(/,/, $s); results in undef $n #6407

Closed
p5pRT opened this issue Mar 31, 2003 · 5 comments
Closed

$s = ""; $n = @a = split(/,/, $s); results in undef $n #6407

p5pRT opened this issue Mar 31, 2003 · 5 comments

Comments

@p5pRT
Copy link

p5pRT commented Mar 31, 2003

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

Searchable as RT21765$

@p5pRT
Copy link
Author

p5pRT commented Mar 31, 2003

From wab@agere.com

Created by wab@agere.com

The following code​:
  $s = "";
  $n = @​a = split(/,/, $s);
  print "a=@​a n=$n\n";

produces​:
  a= n=

But I expect n=0.

I get the expected result if I change the code from
  $n = @​a = split(/,/, $s);
to
  @​a = split(/,/, $s);
  $n = @​a;

I also get the expected result if I predefine @​a as shown below​:
  my @​a;
  $n = @​a = split(/,/, $s);

Perl Info

Flags:
    category=core
    severity=medium

Site configuration information for perl v5.8.0:

Configured by models at Sat Mar 22 12:37:52 EST 2003.

Summary of my perl5 (revision 5.0 version 8 subversion 0) configuration:
  Platform:
    osname=solaris, osvers=2.7, archname=sun4-solaris
    uname='sunos alsun130 5.7 generic_106541-19 sun4u sparc sunw,ultra-2 '
    config_args=''
    hint=previous, useposix=true, d_sigaction=define
    usethreads=undef use5005threads=undef useithreads=undef usemultiplicity=undef
    useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
    use64bitint=undef use64bitall=undef uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='/sopt/Workshop6/SUNWspro/bin/cc', ccflags ='-DDEBUGGING -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
    optimize='-O',
    cppflags='-DDEBUGGING -DDEBUGGING -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64'
    ccversion='Sun WorkShop 6 2000/04/07 C 5.1', gccversion='', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=4321
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
    alignbytes=8, prototype=define
  Linker and Libraries:
    ld='/sopt/Workshop6/SUNWspro/bin/cc', ldflags ='-L/sopt/Workshop6/SUNWspro/WS6/lib -L/usr/lib -L/usr/ccs/lib '
    libpth=/sopt/Workshop6/SUNWspro/WS6/lib /usr/lib /usr/ccs/lib
    libs=-lsocket -lnsl -ldl -lm -lc
    perllibs=-lsocket -lnsl -ldl -lm -lc
    libc=/lib/libc.so, so=so, useshrplib=false, libperl=libperl.a
    gnulibc_version=''
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags=' '
    cccdlflags='-KPIC', lddlflags='-G -L/sopt/Workshop6/SUNWspro/WS6/lib -L/usr/lib -L/usr/ccs/lib'

Locally applied patches:
    


@INC for perl v5.8.0:
    /home/models/common/lang/perl/lib/5.8.0/sun4-solaris
    /home/models/common/lang/perl/lib/5.8.0
    /home/models/common/lang/perl/lib/site_perl/5.8.0/sun4-solaris
    /home/models/common/lang/perl/lib/site_perl/5.8.0
    /home/models/common/lang/perl/lib/site_perl
    .


Environment for perl v5.8.0:
    HOME=/home/models
    LANG (unset)
    LANGUAGE (unset)
    LD_LIBRARY_PATH=/usr/lib:/sopt/SUNWspro/lib:/sopt/exptools/gnu/lib
    LOGDIR (unset)
    PATH=:/home/models/bin:/sopt/netscape/bin:/usr/openwin/bin:/sopt/SUNWspro/bin:/usr/ccs/bin:/usr/bin:/usr/sbin:/usr/ucb:/usr/ccs/bin:/sopt/local/bin:/sopt/dcs/bin:/sopt/addpath/bin:/usr/bin:/usr/ucb:/usr/local/bin:/sopt/exptools/bin:/sopt/exptools/gnu/bin:/sopt/Acrobat3/bin:/home/alctest/access.shells:/home/ads_beta/access.shells:/home/ddts/sol2x_bin:/home/models/bin/perltidy:/home/wab/bin
    PERL_BADLANG (unset)
    SHELL=/bin/ksh

@p5pRT
Copy link
Author

p5pRT commented Apr 2, 2003

From @ysth

On 31 Mar 2003 15​:39​:40 -0000, wab@​agere.com wrote​:

The following code​:
$s = "";
$n = @​a = split(/,/, $s);
print "a=@​a n=$n\n";

produces​:
a= n=

But I expect n=0.

I get the expected result if I change the code from
$n = @​a = split(/,/, $s);
to
@​a = split(/,/, $s);
$n = @​a;

I also get the expected result if I predefine @​a as shown below​:
my @​a;
$n = @​a = split(/,/, $s);

This is triggered by a weird optimization to @​global=split...
that performs the assignment into the global during the split instead
of as a separate operation. Sometime later, I'd like to see this
optimization extended to work on lexicals also, since it seems of
little worth as is (given the sheer amount of extra code it requires
in pp_split, newASSIGNOP, and elsewhere). This could possibly be done
by setting OPf_STACKED and passing split the av as a separate
parameter.

The code to return undef in this case looks pretty intentional, but
since that contradicts both the documentation and common sense, I
think it should be changed to return 0.

Patch is to maint. Added eval{} to former last test since that seems
to be what it expected and I wanted to be able to run the tests to
completion using a 5.8.0 perl.

Inline Patch
--- perl-5.8/t/op/split.t.orig	Tue Feb 18 07:57:52 2003
+++ perl-5.8/t/op/split.t	Tue Apr  1 16:24:34 2003
@@ -6,7 +6,7 @@
     require './test.pl';
 }
 
-plan tests => 50;
+plan tests => 52;
 
 $FS = ':';
 
@@ -280,6 +280,13 @@
 {
     $p="a,b";
     utf8::upgrade $p;
-    @a=split(/[, ]+/,$p);
+    eval { @a=split(/[, ]+/,$p) };
     is ("$@-@a-", '-a b-', '#20912 - split() to array with /[]+/ and utf8');
+}
+
+{
+    is (\@a, \@{"a"}, '@a must be global for following test');
+    $p="";
+    $n = @a = split /,/,$p;
+    is ($n, 0, '#21765 - pmreplroot hack used to return undef for 0 iters');
 }
--- perl-5.8/pp.c.orig	Wed Mar 19 08:52:36 2003
+++ perl-5.8/pp.c	Tue Apr  1 14:44:14 2003
@@ -4785,12 +4785,10 @@
 	if (gimme == G_ARRAY)
 	    RETURN;
     }
-    if (iters || !pm->op_pmreplroot) {
-	GETTARGET;
-	PUSHi(iters);
-	RETURN;
-    }
-    RETPUSHUNDEF;
+
+    GETTARGET;
+    PUSHi(iters);
+    RETURN;
 }
 
 #ifdef USE_5005THREADS
End of Patch.

@p5pRT
Copy link
Author

p5pRT commented Apr 2, 2003

From @rgs

Yitzchak Scott-Thoennes wrote​:

The code to return undef in this case looks pretty intentional, but
since that contradicts both the documentation and common sense, I
think it should be changed to return 0.

Agreed -- thanks, applied to blead as #19135 (with the necessary
adjustments).

Patch is to maint. Added eval{} to former last test since that seems
to be what it expected and I wanted to be able to run the tests to
completion using a 5.8.0 perl.

--
Unfounded is not *NIX

@p5pRT
Copy link
Author

p5pRT commented Apr 3, 2003

From @ysth

On Wed, 2 Apr 2003 21​:57​:05 +0200, rgarciasuarez@​free.fr wrote​:

Yitzchak Scott-Thoennes wrote​:

The code to return undef in this case looks pretty intentional, but
since that contradicts both the documentation and common sense, I
think it should be changed to return 0.

Agreed -- thanks, applied to blead as #19135 (with the necessary
adjustments).

Hmm. Looks like the maint split.t needs to catch up with blead...the
#18195 tests are improved in the blead version to actually fail without
the fix :)

@p5pRT p5pRT closed this as completed Apr 3, 2003
@p5pRT
Copy link
Author

p5pRT commented Apr 3, 2003

@rgs - Status changed from 'new' to 'resolved'

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

No branches or pull requests

1 participant