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

Perl 5.10.0 smart match with m//g fails to update pos #9783

Open
p5pRT opened this issue Jul 1, 2009 · 3 comments
Open

Perl 5.10.0 smart match with m//g fails to update pos #9783

p5pRT opened this issue Jul 1, 2009 · 3 comments

Comments

@p5pRT
Copy link

p5pRT commented Jul 1, 2009

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

Searchable as RT67140$

@p5pRT
Copy link
Author

p5pRT commented Jul 1, 2009

From joejr@vornehm.com

Created by joejr@vornehm.com

The Perl 5.10 smart match operator, when used with a regular expression, does not update the match position returned by the pos() function. A simple example​:

  use feature "​:5.10";
  $x = "abc";
  $x ~~ /abc/g and print "yes\n";
  print "pos is ", (defined pos($x) ? pos($x) : "undef"), "\n";

The output is

  yes
  pos is undef

but should be

  yes
  pos is 3

Changing ~~ to =~ produces the correct output.

This also affects smart matches in while/given statements. That's perhaps the most important use case, where one is trying to parse structured input using m//g and m//gc​:

  while (pos($input) < length($input)) {
  when (/\G for \s*/gcx) {
  ($var, $from, $to) = /\G (\w+) \s* in \s* \(\d+) \s* to \s* (\d+)/gx;
  do_for_loop($var, $from, $to);
  }
  # etc.
  }

I have confirmed this behavior on Perl 5.10.0 patch 34065 for Cygwin 1.5.25, ActiveState Perl 5.10.0 build 1005, and Strawberry Perl 5.10.0.5 (the most recent available stable versions), all running on WinXP SP3.

Perl Info

Flags:
    category=core
    severity=medium

Site configuration information for perl 5.10.0:

Configured by rurban at Mon Jun 30 16:03:19 GMT 2008.

Summary of my perl5 (revision 5 version 10 subversion 0 patch 34065) configuration:
  Platform:
    osname=cygwin, osvers=1.5.25(0.15642), archname=cygwin-thread-multi-64int
    uname='cygwin_nt-5.1 reini 1.5.25(0.15642) 2008-06-12 19:34 i686 cygwin '
    config_args='-de -Dmksymlinks -Dusethreads -Dmad=y -Dusedevel'
    hint=recommended, useposix=true, d_sigaction=define
    useithreads=define, usemultiplicity=define
    useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
    use64bitint=define, use64bitall=undef, uselongdouble=undef
    usemymalloc=y, bincompat5005=undef
  Compiler:
    cc='gcc', ccflags ='-DPERL_USE_SAFE_PUTENV -U__STRICT_ANSI__ -fno-strict-aliasing -pipe -I/usr/local/include',
    optimize='-O3',
    cppflags='-DPERL_USE_SAFE_PUTENV -U__STRICT_ANSI__ -fno-strict-aliasing -pipe -I/usr/local/include'
    ccversion='', gccversion='3.4.4 (cygming special, gdc 0.12, using dmd 0.125)', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=12345678
    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=8, prototype=define
  Linker and Libraries:
    ld='g++', ldflags =' -Wl,--enable-auto-import -Wl,--export-all-symbols -Wl,--stack,8388608 -Wl,--enable-auto-image-base -L/usr/local/lib'
    libpth=/usr/local/lib /usr/lib /lib
    libs=-lgdbm -ldb -ldl -lcrypt -lgdbm_compat
    perllibs=-ldl -lcrypt
    libc=/usr/lib/libc.a, so=dll, useshrplib=true, libperl=libperl.a
    gnulibc_version=''
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=dll, d_dlsymun=undef, ccdlflags=' '
    cccdlflags=' ', lddlflags=' --shared  -Wl,--enable-auto-import -Wl,--export-all-symbols -Wl,--stack,8388608 -Wl,--enable-auto-image-base -L/usr/local/lib'

Locally applied patches:
    MAINT34065
    CYG11 no-bs
    CYG12 no archlib in otherlibdirs
    CYG14 Dynaloader
    CYG15 static-Win32CORE
    Bug#55162 File::Spec::case_tolerant performance


@INC for perl 5.10.0:
    /usr/lib/perl5/5.10/i686-cygwin
    /usr/lib/perl5/5.10
    /usr/lib/perl5/site_perl/5.10/i686-cygwin
    /usr/lib/perl5/site_perl/5.10
    /usr/lib/perl5/vendor_perl/5.10/i686-cygwin
    /usr/lib/perl5/vendor_perl/5.10
    /usr/lib/perl5/vendor_perl/5.10
    /usr/lib/perl5/site_perl/5.8
    /usr/lib/perl5/vendor_perl/5.8
    .


Environment for perl 5.10.0:
    CYGWIN=server
    HOME=/home/Joe
    LANG (unset)
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/usr/bin:/bin
    PERL5LIB=
    PERLDOC_PAGER=less
    PERL_BADLANG (unset)
    SHELL (unset)


@p5pRT
Copy link
Author

p5pRT commented Jul 22, 2009

From @iabyn

On Wed, Jul 01, 2009 at 12​:15​:53PM -0700, Joe Vornehm wrote​:

The Perl 5.10 smart match operator, when used with a regular expression, does not update the match position returned by the pos() function. A simple example​:

use feature "&#8203;:5\.10";
$x = "abc";
$x ~~ /abc/g and print "yes\\n";
print "pos is "\, \(defined pos\($x\) ? pos\($x\) : "undef"\)\, "\\n";

The output is

yes
pos is undef

but should be

yes
pos is 3

Changing ~~ to =~ produces the correct output.

This also affects smart matches in while/given statements. That's perhaps the most important use case, where one is trying to parse structured input using m//g and m//gc​:

while \(pos\($input\) \< length\($input\)\) \{
  when \(/\\G for \\s\*/gcx\) \{
    \($var\, $from\, $to\) = /\\G \(\\w\+\) \\s\* in \\s\* \\\(\\d\+\) \\s\* to \\s\* \(\\d\+\)/gx;
    do\_for\_loop\($var\, $from\, $to\);
  \}
  \# etc\.
\}

I have confirmed this behavior on Perl 5.10.0 patch 34065 for Cygwin 1.5.25, ActiveState Perl 5.10.0 build 1005, and Strawberry Perl 5.10.0.5 (the most recent available stable versions), all running on WinXP SP3.

Also confirmed in maint and blead​:
GitLive-blead-1642-gd17935e, GitLive-maint-5.10-1622-g836440f

--
Dave's first rule of Opera​:
If something needs saying, say it​: don't warble it.

@p5pRT
Copy link
Author

p5pRT commented Jul 22, 2009

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

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

2 participants