Skip to content

s// /g weirdness #3516

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

Closed
p5pRT opened this issue Mar 4, 2001 · 2 comments
Closed

s// /g weirdness #3516

p5pRT opened this issue Mar 4, 2001 · 2 comments

Comments

@p5pRT
Copy link

p5pRT commented Mar 4, 2001

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

Searchable as RT5959$

@p5pRT
Copy link
Author

p5pRT commented Mar 4, 2001

From @simoncozens

Maybe this is something obvious I missed, and I know I'm dealing with
somewhat undefined semantics, but...​:

  $_ = "this/is/a/test"; y#/#\n#; s// /g; print

prints

t h i s
i s
a
t e s t

as I'd expect, whereas

  $_ = "this/is/a/test"; s#/#\n#g; s// /g; print

prints

this
is
a
test

which I wouldn't. s//foo/ wants to be the first match in the program
or it doesn't match.

Perl Info

Flags:
    category=core
    severity=low

Site configuration information for perl v5.6.0:

Configured by bod at Tue Feb 27 03:27:16 EST 2001.

Summary of my perl5 (revision 5.0 version 6 subversion 0) configuration:
  Platform:
    osname=linux, osvers=2.2.18, archname=i386-linux
    uname='linux duende 2.2.18 #1 thu dec 28 14:51:40 est 2000 i686 unknown '
    config_args='-Dccflags=-DDEBIAN -Darchname=i386-linux -Dprefix=/usr -Dprivlib=/usr/share/perl/5.6.0 -Darchlib=/usr/lib/perl/5.6.0 -Dvendorprefix=/usr -Dvendorlib=/usr/share/perl5 -Dvendorarch=/usr/lib/perl5 -Dsiteprefix=/usr/local -Dsitelib=/usr/local/share/perl/5.6.0 -Dsitearch=/usr/local/lib/perl/5.6.0 -Dman1dir=/usr/share/man/man1 -Dman3dir=/usr/share/man/man3 -Dman1ext=1 -Dman3ext=3 -Dpager=/usr/bin/pager -Uafs -Ud_csh -Uusesfio -Duseshrplib -Dlibperl=libperl.so.5.6.0 -Dd_dosuid -des'
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=undef use5005threads=undef useithreads=undef usemultiplicity=undef
    useperlio=undef d_sfio=undef uselargefiles=define 
    use64bitint=undef use64bitall=undef uselongdouble=undef usesocks=undef
  Compiler:
    cc='cc', optimize='-O2', gccversion=2.95.3 20010219 (prerelease)
    cppflags='-DDEBIAN -fno-strict-aliasing -I/usr/local/include'
    ccflags ='-DDEBIAN -fno-strict-aliasing -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64'
    stdchar='char', d_stdstdio=define, usevfork=false
    intsize=4, longsize=4, ptrsize=4, doublesize=8
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
    alignbytes=4, usemymalloc=n, prototype=define
  Linker and Libraries:
    ld='cc', ldflags =' -L/usr/local/lib'
    libpth=/usr/local/lib /lib /usr/lib
    libs=-lnsl -ldl -lm -lc -lcrypt
    libc=/lib/libc-2.2.2.so, so=so, useshrplib=true, libperl=libperl.so.5.6.0
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynamic'
    cccdlflags='-fPIC', lddlflags='-shared -L/usr/local/lib'

Locally applied patches:
    


@INC for perl v5.6.0:
    /usr/local/lib/perl/5.6.0
    /usr/local/share/perl/5.6.0
    /usr/lib/perl5
    /usr/share/perl5
    /usr/lib/perl/5.6.0
    /usr/share/perl/5.6.0
    /usr/lib/perl5/5.6/i386-linux
    /usr/lib/perl5/5.6
    /usr/lib/perl5/5.005/i386-linux
    .


Environment for perl v5.6.0:
    HOME=/home/simon
    LANG (unset)
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/home/simon/bin:/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/games:/usr/local/sbin:/usr/sbin:/sbin
    PERL_BADLANG (unset)
    SHELL=/usr/local/bin/zsh

@p5pRT
Copy link
Author

p5pRT commented Mar 4, 2001

From @pjscott

At 02​:36 PM 3/4/2001 +0000, simon@​netthink.co.uk wrote​:

Maybe this is something obvious I missed, and I know I'm dealing with
somewhat undefined semantics, but...​:

$_ = "this/is/a/test"; y#/#\n#; s// /g; print

prints

t h i s
i s
a
t e s t

as I'd expect, whereas

$_ = "this/is/a/test"; s#/#\n#g; s// /g; print

prints

this
is
a
test

which I wouldn't.

No bug. The empty regular expression is defined as matching the last successfully matched regex; see perlop/"Regexp Quote-Like Operators".

The man page could stand some mention of the behavior you did expect, though :-)

Inline Patch
--- pod/perlop.pod.orig Sun Mar  4 07:40:18 2001
+++ pod/perlop.pod      Sun Mar  4 07:44:22 2001
@@ -808,6 +808,8 @@
 
 If the PATTERN evaluates to the empty string, the last
 I<successfully> matched regular expression is used instead.
+If there is no previous regular expression, successfully matched or
+otherwise, an empty PATTERN matches an empty substring.
 
 If the C</g> option is not used, C<m//> in list context returns a
 list consisting of the subexpressions matched by the parentheses in the

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