Skip to content

Surprised that $^N action works if string is global, fails if string is local #8170

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 Oct 26, 2005 · 6 comments
Closed

Comments

@p5pRT
Copy link

p5pRT commented Oct 26, 2005

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

Searchable as RT37543$

@p5pRT
Copy link
Author

p5pRT commented Oct 26, 2005

From [email protected]

Created by [email protected]

Surprised that $^N does not work on local (my) variable in a sub but
instead
requires a global variable. Following code works OK since '$foundstr'
is global, but
remove '#' (making the $foundstr variable local to sub) and code
crashes​:

#START OF CODE
&findABC('abcd');
&findABC('abcd'); # 2nd call should yield identical results

sub findABC
{
  my $txt = shift;
  # my ($foundstr); # uncomment this statement to see problem

  if ($txt =~
  m/
  (ABC) (?{$foundstr = $^N})
  /ix
  )
  {
  printf "after regex \$foundstr = '$foundstr'\n";
  };
  }

# END OF CODE

# EXAMPLE OUTPUT​:
Case 1) with global $foundstr​:

after regex $foundstr = 'abc'
after regex $foundstr = 'abc'

Case 2) with "my $foundstr;" statement added to sub​:

after regex $foundstr = 'abc'
Use of uninitialized value in concatenation (.) or string at problem.pl
line 15.

after regex $foundstr = ''

# END OF EXAMPLE OUTPUT

Perl Info

Flags:
    category=core
    severity=medium

Site configuration information for perl v5.8.7:

Configured by builder at Mon Jun  6 13:36:05 2005.

Summary of my perl5 (revision 5 version 8 subversion 7) configuration:
  Platform:
    osname=MSWin32, osvers=5.0, archname=MSWin32-x86-multi-thread
    uname=''
    config_args='undef'
    hint=recommended, useposix=true, d_sigaction=undef
    usethreads=define use5005threads=undef useithreads=define
usemultiplicity=define
    useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
    use64bitint=undef use64bitall=undef uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='cl', ccflags ='-nologo -Gf -W3 -MD -Zi -DNDEBUG -O1 -DWIN32
-D_CONSOLE -DNO_STRICT -DHAVE_DES_FCRYPT -DBUILT_BY_ACTIVESTATE
-DNO_HASH_SEED -DUSE_SITECUSTOMIZE -DPERL_IMPLICIT_CONTEXT
-DPERL_IMPLICIT_SYS -DUSE_PERLIO -DPERL_MSVCRT_READFIX',
    optimize='-MD -Zi -DNDEBUG -O1',
    cppflags='-DWIN32'
    ccversion='12.00.8804', gccversion='', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
    d_longlong=undef, longlongsize=8, d_longdbl=define, longdblsize=10
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='__int64',
lseeksize=8
    alignbytes=8, prototype=define
  Linker and Libraries:
    ld='link', ldflags ='-nologo -nodefaultlib -debug -opt:ref,icf 
-libpath:"C:\Perl\lib\CORE"  -machine:x86'
    libpth=\lib
    libs=  oldnames.lib kernel32.lib user32.lib gdi32.lib winspool.lib 
comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib 
netapi32.lib uuid.lib ws2_32.lib mpr.lib winmm.lib  version.lib
odbc32.lib odbccp32.lib msvcrt.lib
    perllibs=  oldnames.lib kernel32.lib user32.lib gdi32.lib
winspool.lib  comdlg32.lib advapi32.lib shell32.lib ole32.lib
oleaut32.lib  netapi32.lib uuid.lib ws2_32.lib mpr.lib winmm.lib 
version.lib odbc32.lib odbccp32.lib msvcrt.lib
    libc=msvcrt.lib, so=dll, useshrplib=yes, libperl=perl58.lib
    gnulibc_version='undef'
  Dynamic Linking:
    dlsrc=dl_win32.xs, dlext=dll, d_dlsymun=undef, ccdlflags=' '
    cccdlflags=' ', lddlflags='-dll -nologo -nodefaultlib -debug
-opt:ref,icf  -libpath:"C:\Perl\lib\CORE"  -machine:x86'

Locally applied patches:
    ACTIVEPERL_LOCAL_PATCHES_ENTRY
    #  if !defined(PERL_DARWIN)
    Iin_load_module moved for compatibility with build 806
    #  endif
    #  if defined(__hpux)
    Avoid signal flag SA_RESTART for older versions of HP-UX
    #  endif
    PerlEx hacks for CGI::Carp
    Less verbose ExtUtils::Install and Pod::Find
    instmodsh upgraded from ExtUtils-MakeMaker-6.25
    24699 ICMP_UNREACHABLE handling in Net::Ping
    21540 Fix backward-compatibility issues in if.pm


@INC for perl v5.8.7:
    C:/perl/lib
    C:/perl/site/lib
    .


Environment for perl v5.8.7:
    HOME (unset)
    LANG (unset)
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
   
PATH=C:\Perl\bin\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\PROGRA~1\COMMON~1\Odbc\FILEMA~1;H:\Program
Files\ATI\Control Panel;C:\Program Files\Common Files\Ulead
Systems\MPEG;H:\Program Files\Ulead\Ulead DVD MovieFactory 3
SE;c:\wld\bin
    PERL_BADLANG (unset)
    SHELL (unset)

@p5pRT
Copy link
Author

p5pRT commented Oct 27, 2005

From [email protected]

On Oct 26, via RT and UNEXPECTED_DATA_AFTERdevanney@​prodigy.netsaid​:

Surprised that $^N does not work on local (my) variable in a sub but
instead
requires a global variable. Following code works OK since '$foundstr'
is global, but
remove '#' (making the $foundstr variable local to sub) and code
crashes​:

It's not that $^N doesn't work. It's that (?{ $foundstr = $^N }) ends up
being a closure around the lexical $foundstr. This is a known bug. The
first time the regex is compiled, the (?{ ... }) refers to a specific
lexical. Subsequent calls to the regex will still be operating on that
first lexical.

   printf "after regex \\$foundstr = '$foundstr'\\n";

Don't use printf() unless you mean "print a formatted string".

--
Jeff "japhy" Pinyan % How can we ever be the sold short or
RPI Acacia Brother #734 % the cheated, we who for every service
http​://www.perlmonks.org/ % have long ago been overpaid?
http​://princeton.pm.org/ % -- Meister Eckhart

@p5pRT
Copy link
Author

p5pRT commented Oct 27, 2005

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

@p5pRT
Copy link
Author

p5pRT commented Oct 28, 2005

From [email protected]

thanks very much...

"japhy@​perlmonk.org via RT" wrote​:

On Oct 26, via RT and UNEXPECTED_DATA_AFTERdevanney@​prodigy.netsaid​:

Surprised that $^N does not work on local (my) variable in a sub but
instead
requires a global variable. Following code works OK since '$foundstr'
is global, but
remove '#' (making the $foundstr variable local to sub) and code
crashes​:

It's not that $^N doesn't work. It's that (?{ $foundstr = $^N }) ends up
being a closure around the lexical $foundstr. This is a known bug. The
first time the regex is compiled, the (?{ ... }) refers to a specific
lexical. Subsequent calls to the regex will still be operating on that
first lexical.

   printf "after regex \\$foundstr = '$foundstr'\\n";

Don't use printf() unless you mean "print a formatted string".

--
Jeff "japhy" Pinyan % How can we ever be the sold short or
RPI Acacia Brother #734 % the cheated, we who for every service
http​://www.perlmonks.org/ % have long ago been overpaid?
http​://princeton.pm.org/ % -- Meister Eckhart

@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