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

Regex "(?{ code })" not working. #7849

Closed
p5pRT opened this issue Mar 22, 2005 · 6 comments
Closed

Regex "(?{ code })" not working. #7849

p5pRT opened this issue Mar 22, 2005 · 6 comments

Comments

@p5pRT
Copy link

p5pRT commented Mar 22, 2005

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

Searchable as RT34547$

@p5pRT
Copy link
Author

p5pRT commented Mar 22, 2005

From lidden@yahoo.se

Created by lidden@yahoo.se

The following sub is only working the first time it is called.

<code>
sub get_people{
  my $desc = shift;

  my @​cast;

  $desc =~ m§I rollerna​:\s*(?​:([\w ]+)(?​:,|)(?{ push @​cast, $1; })\s*)+\.§i;

  print join ' : ', @​cast, "\n";
}

my $rant = 'Blah blah, blah. I rollerna​: Peter Weller, Nancy Allen, Ronny Cox. Regi​: Paul Verhoeven. (RoboCop)';

get_people($rant);
get_people($rant);
</code>
<output>
Variable "@​cast" will not stay shared at (re_eval 6) line 1.
Peter Weller : Nancy Allen : Ronny Cox :

</output>

Tried with perl5.8.6, perl5.9.1 and this blead version.
perl5.8.6 does not give the warning.

/Stefan Lidman

Perl Info

Flags:
    category=core
    severity=low

Site configuration information for perl v5.9.2:

Configured by stefan at Thu Mar 17 03:03:18 CET 2005.

Summary of my perl5 (revision 5 version 9 subversion 2 patch 24039) configuration:
  Platform:
    osname=linux, osvers=2.6.11.4, archname=i686-linux-thread-multi-64int
    uname='linux puce 2.6.11.4 #1 wed mar 16 05:58:54 cet 2005 i686 unknown unknown gnulinux '
    config_args=''
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=define useithreads=define usemultiplicity=define
    useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
    use64bitint=define use64bitall=undef uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='gcc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -fno-strict-aliasing -pipe -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
    optimize='-O3 -funroll-loops',
    cppflags='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -fno-strict-aliasing -pipe -I/usr/local/include'
    ccversion='', gccversion='3.4.3', 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=4, prototype=define
  Linker and Libraries:
    ld='gcc', ldflags =' -L/usr/local/lib'
    libpth=/usr/local/lib /lib /usr/lib
    libs=-lnsl -ldb -ldl -lm -lcrypt -lutil -lpthread -lc
    perllibs=-lnsl -ldl -lm -lcrypt -lutil -lpthread -lc
    libc=/lib/libc-2.3.2.so, so=so, useshrplib=false, libperl=libperl.a
    gnulibc_version='2.3.2'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E'
    cccdlflags='-fpic', lddlflags='-shared -L/usr/local/lib'

Locally applied patches:
    DEVEL22511


@INC for perl v5.9.2:
    /usr/local/bleadperl/lib/5.9.2/i686-linux-thread-multi-64int
    /usr/local/bleadperl/lib/5.9.2
    /usr/local/bleadperl/lib/site_perl/5.9.2/i686-linux-thread-multi-64int
    /usr/local/bleadperl/lib/site_perl/5.9.2
    /usr/local/bleadperl/lib/site_perl
    /home/stefan/prog/perl
    .


Environment for perl v5.9.2:
    HOME=/home/stefan
    LANG (unset)
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=./bin:./bin:/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin:/home/stefan/bin:/usr/X11R6/bin:/home/stefan/bin:/usr/X11R6/bin
    PERLDOC_PAGER=less -j8 -iMfsRF
    PERL_BADLANG (unset)
    SHELL=/bin/bash

@p5pRT
Copy link
Author

p5pRT commented Mar 23, 2005

From @demerphq

On 22 Mar 2005 22​:13​:23 -0000, via RT lidden @​ yahoo. se
<perlbug-followup@​perl.org> wrote​:

# New Ticket Created by lidden@​yahoo.se
# Please include the string​: [perl #34547]
# in the subject line of all future correspondence about this issue.
# <URL​: https://rt-archive.perl.org/perl5/Ticket/Display.html?id=34547 >

This is a bug report for perl from lidden@​yahoo.se,
generated with the help of perlbug 1.35 running under perl v5.9.2.

-----------------------------------------------------------------
[Please enter your report here]

The following sub is only working the first time it is called.

<code>
sub get_people{
my $desc = shift;

my @​cast;

$desc =~ m§I rollerna​:\s*(?​:([\w ]+)(?​:,|)(?{ push @​cast, $1; })\s*)+\.§i;

print join ' : ', @​cast, "\n";
}

my $rant = 'Blah blah, blah. I rollerna​: Peter Weller, Nancy Allen, Ronny Cox. Regi​: Paul Verhoeven. (RoboCop)';

get_people($rant);
get_people($rant);
</code>
<output>
Variable "@​cast" will not stay shared at (re_eval 6) line 1.
Peter Weller : Nancy Allen : Ronny Cox :

</output>

Tried with perl5.8.6, perl5.9.1 and this blead version.
perl5.8.6 does not give the warning.

The code inside the regex is a closure on the original lexical copy.
The workaround to this is to use package vars instead.
The warning in later perls is to tell what is happening. It might be
nice to change the message to suggest using a package var instead in
this circumstance. Tho I guess diagnostics.pm should handle that.

sub get_people{
  my $desc = shift;

  our @​cast;
  local @​cast;

  $desc =~ m§I rollerna​:\s*(?​:([\w ]+)(?​:,|)(?{ push @​cast, $1; })\s*)+\.§i;

  print join ' : ', @​cast, "\n";
}

my $rant = 'Blah blah, blah. I rollerna​: Peter Weller, Nancy Allen,
Ronny Cox. Regi​: Paul Verhoeven. (RoboCop)';

get_people($rant);
get_people($rant);
__END__
Peter Weller : Nancy Allen : Ronny Cox :
Peter Weller : Nancy Allen : Ronny Cox :

--
perl -Mre=debug -e "/just|another|perl|hacker/"

@p5pRT
Copy link
Author

p5pRT commented Mar 23, 2005

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

@p5pRT
Copy link
Author

p5pRT commented Mar 23, 2005

From @iabyn

On Wed, Mar 23, 2005 at 11​:47​:19AM +0100, demerphq wrote​:

The code inside the regex is a closure on the original lexical copy.
The workaround to this is to use package vars instead.
The warning in later perls is to tell what is happening. It might be
nice to change the message to suggest using a package var instead in
this circumstance. Tho I guess diagnostics.pm should handle that.

The behaviour is buggy nevertheless, and I'm still planning to fix it at
some point (should have more time on my hands soon). The warning appears
in 5.9.1 because I cleaned up the closure code a lot; but once I've
fixed the regex stuff the warning will go away, so there's no need to add
to diagnostics.pm.

Dave

--
You live and learn (although usually you just live).

@p5pRT
Copy link
Author

p5pRT commented Jun 14, 2012

From @cpansprout

This has been fixed by the commits leading up to eb58a7e.

@p5pRT
Copy link
Author

p5pRT commented Jun 14, 2012

@cpansprout - Status changed from 'open' 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