develooper Front page | perl.perl5.porters | Postings from January 2001

[ID 20010122.092] $` not updated by tr/// access

From:
gansok
Date:
January 22, 2001 16:36
Subject:
[ID 20010122.092] $` not updated by tr/// access
Message ID:
3A687348.BA5543B1@digisle.net
This is a bug report for perl from gansok@digisle.net,
generated with the help of perlbug 1.28 running under perl v5.6.0.


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

Note the following script:

#! perl -w

$_ = '1x2x3';
s/x/bad()/eg;
print "bad:  $_\n";

$_ = '1x2x3';
s/x/good()/eg;
print "good: $_\n";

sub bad {
    my $c = ($` =~ tr/0-9//);
    return "<$c>";
}

sub good {
    my $d = $`;
    my $c = ($d =~ tr/0-9//);
    return "<$c>";
}

__END__

The output (on several Perl builds, up to 5.6.0, on both Windows and
Solaris) is

bad:  1<1>2<1>3
good: 1<1>2<2>3

Apparently on the second substitution, good() sees a value for $` of
'1x2' (questionable, but if what we should be seeing is a piece of 
the original string, not reflecting earlier substitutions, it is 
acceptable).  bad(), however,sees a $` of '1' -- which is the $` 
value from the first substitution.

My guess (and I've not delved into the Perl internals) is that 
whatever logic is set up to notice that $` is being accessed and
the value needs to be refreshed is not being triggered on a 
tr/// access.

Gary Ansok
ansok@alumni.caltech.edu       or     gansok@digisle.net

[Please do not change anything below this line]
-----------------------------------------------------------------
---
Flags:
    category=core
    severity=low
---
Site configuration information for perl v5.6.0:

Configured by gansok at Tue Oct 31 18:30:54 2000.

Summary of my perl5 (revision 5 version 6 subversion 0) configuration:
  Platform:
    osname=MSWin32, osvers=4.0, archname=MSWin32-x86-multi-thread
    uname=''
    config_args='undef'
    hint=recommended, useposix=true, d_sigaction=undef
    usethreads=undef use5005threads=undef useithreads=define
usemultiplicity=define
    useperlio=undef d_sfio=undef uselargefiles=undef 
    use64bitint=undef use64bitall=undef uselongdouble=undef
usesocks=undef
  Compiler:
    cc='cl', optimize='-O1 -MD -DNDEBUG', gccversion=
    cppflags='-DWIN32'
    ccflags ='-O1 -MD -DNDEBUG -DWIN32 -D_CONSOLE -DNO_STRICT
-DHAVE_DES_FCRYPT  -DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS
-DPERL_MSVCRT_READFIX'
    stdchar='char', d_stdstdio=define, usevfork=false
    intsize=4, longsize=4, ptrsize=4, doublesize=8
    d_longlong=undef, longlongsize=8, d_longdbl=define, longdblsize=10
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t',
lseeksize=4
    alignbytes=8, usemymalloc=n, prototype=define
  Linker and Libraries:
    ld='link', ldflags ='-nologo -nodefaultlib -release 
-libpath:"D:\Perl\lib\CORE"  -machine:x86'
    libpth="D:\Perl\lib\CORE"
    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 wsock32.lib mpr.lib winmm.lib  version.lib
odbc32.lib odbccp32.lib msvcrt.lib
    libc=msvcrt.lib, so=dll, useshrplib=yes, libperl=perl56.lib
  Dynamic Linking:
    dlsrc=dl_win32.xs, dlext=dll, d_dlsymun=undef, ccdlflags=' '
    cccdlflags=' ', lddlflags='-dll -nologo -nodefaultlib -release 
-libpath:"D:\Perl\lib\CORE"  -machine:x86'

Locally applied patches:
    ACTIVEPERL_LOCAL_PATCHES_ENTRY

---
@INC for perl v5.6.0:
    D:/Perl/lib
    D:/Perl/site/lib
    .

---
Environment for perl v5.6.0:
    HOME (unset)
    LANG (unset)
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
   
PATH=D:\Perl\bin\;c:\ntreskit\posix;C:\WINNT\system32;C:\WINNT;C:\Program
Files\Vantive32;C:\Program
Files\Symantec\pcAnywhere\;;D:\mod_perl\Perl\5.00503\bin\mswin32-x86;D:\mod_perl\Perl\5.00503\bin
    PERL_BADLANG (unset)
    SHELL (unset)




nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About