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

[bug? 5.6.0] \G in split pattern #3029

Open
p5pRT opened this issue Dec 23, 2000 · 5 comments
Open

[bug? 5.6.0] \G in split pattern #3029

p5pRT opened this issue Dec 23, 2000 · 5 comments

Comments

@p5pRT
Copy link

p5pRT commented Dec 23, 2000

Migrated from rt.perl.org#5004 (status was 'open')

Searchable as RT5004$

@p5pRT
Copy link
Author

p5pRT commented Dec 23, 2000

From @hvds

Created by @hvds

[fixed misassigned from/created after github migration]

Not sure if this is a bug, but I thought it worth mentioning for
consideration.

crypt% ./perl -wle 'print join "*", split /\G(an|.)/, shift' banana
*b*anana
crypt%

I had hoped it would print something like "*b**an**an**a*". Result
is the same under bleadperl.

Perl Info

Flags:
    ack=no
    category=core
    severity=low

Site configuration information for perl v5.6.0:

Configured by hv at Thu Mar 23 11:41:17 GMT 2000.

Summary of my perl5 (revision 5.0 version 6 subversion 0) configuration:
  Platform:
    osname=linux, osvers=2.2.5-16, archname=i686-linux-64int
    uname='linux crypt.compulink.co.uk 2.2.5-16 #1 sun may 30 23:00:18 bst 1999 i686 unknown '
    config_args='-des -Doptimize=-g -O6 -Dprefix=/opt/perl-5.6.0.64bit -Duse64bitint'
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=undef use5005threads=undef useithreads=undef usemultiplicity=undef
    useperlio=undef d_sfio=undef uselargefiles=define 
    use64bitint=define use64bitall=undef uselongdouble=undef usesocks=undef
  Compiler:
    cc='cc', optimize='-g -O6', gccversion=egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)
    cppflags='-DDEBUGGING -fno-strict-aliasing'
    ccflags ='-DDEBUGGING -fno-strict-aliasing -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 long', ivsize=8, 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 -lndbm -lgdbm -ldb -ldl -lm -lc -lposix -lcrypt
    libc=/lib/libc-2.1.1.so, so=so, useshrplib=false, libperl=libperl.a
  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:
    /opt/perl-5.6.0.64bit/lib/5.6.0/i686-linux-64int
    /opt/perl-5.6.0.64bit/lib/5.6.0
    /opt/perl-5.6.0.64bit/lib/site_perl/5.6.0/i686-linux-64int
    /opt/perl-5.6.0.64bit/lib/site_perl/5.6.0
    /opt/perl-5.6.0.64bit/lib/site_perl
    .


Environment for perl v5.6.0:
    HOME=/home/hv
    LANG (unset)
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/home/hv/bin:/usr/bin:/usr/local/bin:/bin:/usr/X11R6/bin
    PERL_BADLANG (unset)
    SHELL=/bin/bash


@p5pRT
Copy link
Author

p5pRT commented Apr 28, 2010

From @chorny

Same result on 5.12.0.

On Sat Dec 23 00​:12​:51 2000, hv@​crypt.compulink.co.uk wrote​:

Not sure if this is a bug, but I thought it worth mentioning for
consideration.

crypt% ./perl -wle 'print join "*", split /\G(an|.)/, shift' banana
*b*anana
crypt%

I had hoped it would print something like "*b**an**an**a*". Result
is the same under bleadperl.

--
Alexandr Ciornii, http​://chorny.net

@p5pRT
Copy link
Author

p5pRT commented Apr 28, 2010

From [Unknown Contact. See original ticket]

Same result on 5.12.0.

On Sat Dec 23 00​:12​:51 2000, hv@​crypt.compulink.co.uk wrote​:

Not sure if this is a bug, but I thought it worth mentioning for
consideration.

crypt% ./perl -wle 'print join "*", split /\G(an|.)/, shift' banana
*b*anana
crypt%

I had hoped it would print something like "*b**an**an**a*". Result
is the same under bleadperl.

--
Alexandr Ciornii, http​://chorny.net

@p5pRT
Copy link
Author

p5pRT commented Jul 4, 2016

From @dcollinsn

Is \G intended to be meaningful in an argument to split? Instrumenting two variations tells me that \G and pos() do not work within split//​:

  dcollins@​nightshade64​:~/toolchain/perl/t$ ./perl -Dr -le 'print join("*", split(/(?{print "POS​: " . pos() . "\n";})\G(.)/, "banana"))'
  Compiling REx "(?{print %"POS​: %" . pos() . %"\n%";})\G(.)"
  Final program​:
  1​: EVAL (4)
  4​: GPOS (5)
  5​: OPEN1 (7)
  7​: REG_ANY (8)
  8​: CLOSE1 (10)
  10​: END (0)
  anchored(GPOS) GPOS​:0 minlen 1 with eval
  Enabling $` $& $' support (0x7).

  EXECUTING...

  Matching REx "(?{print %"POS​: %" . pos() . %"\n%";})\G(.)" against "banana"
  0 <> <banana> | 0| 1​:EVAL(4)
  POS​: 0

  0 <> <banana> | 0| 4​:GPOS(5)
  0 <> <banana> | 0| 5​:OPEN1(7)
  0 <> <banana> | 0| 7​:REG_ANY(8)
  1 <b> <anana> | 0| 8​:CLOSE1(10)
  1 <b> <anana> | 0| 10​:END(0)
  Match successful!
  Matching REx "(?{print %"POS​: %" . pos() . %"\n%";})\G(.)" against "anana"
  0 <> <banana> | 0| 1​:EVAL(4)
  POS​: 0

  0 <> <banana> | 0| 4​:GPOS(5)
  0 <> <banana> | 0| 5​:OPEN1(7)
  0 <> <banana> | 0| 7​:REG_ANY(8)
  1 <b> <anana> | 0| 8​:CLOSE1(10)
  1 <b> <anana> | 0| 10​:END(0)
  Match possible, but length=1 is smaller than requested=2, failing!
  Match failed
  *b*anana
 
 
  dcollins@​nightshade64​:~/toolchain/perl/t$ ./perl -Dr -le 'while ("banana" =~ /(?{print "POS​: " . pos() . "\n";})\G(.)/g) {print "$&\n";}'
  Compiling REx "(?{print %"POS​: %" . pos() . %"\n%";})\G(.)"
  Final program​:
  1​: EVAL (4)
  4​: GPOS (5)
  5​: OPEN1 (7)
  7​: REG_ANY (8)
  8​: CLOSE1 (10)
  10​: END (0)
  anchored(GPOS) GPOS​:0 minlen 1 with eval
  Enabling $` $&amp; $' support (0x7).

  EXECUTING...

  Matching REx "(?{print %"POS​: %" . pos() . %"\n%";})\G(.)" against "banana"
  0 <> <banana> | 0| 1​:EVAL(4)
  POS​: 0

  0 <> <banana> | 0| 4​:GPOS(5)
  0 <> <banana> | 0| 5​:OPEN1(7)
  0 <> <banana> | 0| 7​:REG_ANY(8)
  1 <b> <anana> | 0| 8​:CLOSE1(10)
  1 <b> <anana> | 0| 10​:END(0)
  Match successful!
  b

  Matching REx "(?{print %"POS​: %" . pos() . %"\n%";})\G(.)" against "anana"
  1 <b> <anana> | 0| 1​:EVAL(4)
  POS​: 1

  1 <b> <anana> | 0| 4​:GPOS(5)
  1 <b> <anana> | 0| 5​:OPEN1(7)
  1 <b> <anana> | 0| 7​:REG_ANY(8)
  2 <ba> <nana> | 0| 8​:CLOSE1(10)
  2 <ba> <nana> | 0| 10​:END(0)
  Match successful!
  a

  Matching REx "(?{print %"POS​: %" . pos() . %"\n%";})\G(.)" against "nana"
  2 <ba> <nana> | 0| 1​:EVAL(4)
  POS​: 2

  2 <ba> <nana> | 0| 4​:GPOS(5)
  2 <ba> <nana> | 0| 5​:OPEN1(7)
  2 <ba> <nana> | 0| 7​:REG_ANY(8)
  3 <ban> <ana> | 0| 8​:CLOSE1(10)
  3 <ban> <ana> | 0| 10​:END(0)
  Match successful!
  n

  Matching REx "(?{print %"POS​: %" . pos() . %"\n%";})\G(.)" against "ana"
  3 <ban> <ana> | 0| 1​:EVAL(4)
  POS​: 3

  3 <ban> <ana> | 0| 4​:GPOS(5)
  3 <ban> <ana> | 0| 5​:OPEN1(7)
  3 <ban> <ana> | 0| 7​:REG_ANY(8)
  4 <bana> <na> | 0| 8​:CLOSE1(10)
  4 <bana> <na> | 0| 10​:END(0)
  Match successful!
  a

  Matching REx "(?{print %"POS​: %" . pos() . %"\n%";})\G(.)" against "na"
  4 <bana> <na> | 0| 1​:EVAL(4)
  POS​: 4

  4 <bana> <na> | 0| 4​:GPOS(5)
  4 <bana> <na> | 0| 5​:OPEN1(7)
  4 <bana> <na> | 0| 7​:REG_ANY(8)
  5 <banan> <a> | 0| 8​:CLOSE1(10)
  5 <banan> <a> | 0| 10​:END(0)
  Match successful!
  n

  Matching REx "(?{print %"POS​: %" . pos() . %"\n%";})\G(.)" against "a"
  5 <banan> <a> | 0| 1​:EVAL(4)
  POS​: 5

  5 <banan> <a> | 0| 4​:GPOS(5)
  5 <banan> <a> | 0| 5​:OPEN1(7)
  5 <banan> <a> | 0| 7​:REG_ANY(8)
  6 <banana> <> | 0| 8​:CLOSE1(10)
  6 <banana> <> | 0| 10​:END(0)
  Match successful!
  a

  Matching REx "(?{print %"POS​: %" . pos() . %"\n%";})\G(.)" against ""
  Regex match can't succeed, so not even tried

Is this /supposed/ to work? is pos() or \G in any way a feature that is useful in split//?

@demerphq
Copy link
Collaborator

/g is not allowed on a split argument, which i think might fix this. I am torn about whether we should fix this TBH.

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

3 participants