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

[ID 20010101.003] Perl bug: Incorrect handling of $1 in firstpass in (?{ code })

Thread Next
From:
ttel5535
Date:
January 1, 2001 14:14
Subject:
[ID 20010101.003] Perl bug: Incorrect handling of $1 in firstpass in (?{ code })
Message ID:
Pine.LNX.4.21.0101012312220.5924-100000@artax.karlin.mff.cuni.cz

This is a bug report for perl from ttel5535@artax.karlin.mff.cuni.cz,
generated with the help of perlbug 1.26 running under perl 5.00503.


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

The $1 variable is not correctly set in the first (and matching) pass in the 
(?{ code }). See the following example:

#!/usr/bin/perl

# Try uncomment this
#"q" =~ m{ ^(q) (?{}) }x;

for ("a:", "b: ", "c:") {

  if ( m{
          ([a-z])
          (?{
             printf "Inside:\n";
             printf '$^R' . " == $^R\n";
             printf '$1' . " == $1\n";
             $1; # this establishes the $^R value for the first cycle
                 # at least outside,
                 # during other cycles it is established as it should
                 # (also in "At the end" section)
          })
          :$ 
          (?{
             printf "At the end:\n";
             printf '$^R' . " == $^R\n";
             printf '$1' . " == $1\n";
          })
        }x
     ) 
  {
    printf "Outside:\n";
    printf '$^R' . " == $^R\n";
    printf '$1' . " == $1\n";
    printf "\n"
  }
}

####### end of example #######

Actual output:

~/pokus/perl> bug
Inside:
$^R ==
$1 ==
At the end:
$^R ==
$1 ==
Outside:
$^R == 1
$1 == a

Inside:
$^R == 1
$1 == c
At the end:
$^R == c
$1 == c
Outside:
$^R == 1
$1 == c

What I would expect:
~/pokus/perl> bug
Inside:
$^R ==
$1 == a
At the end:
$^R == a
$1 == a
Outside:
$^R == 1
$1 == a

Inside:
$^R == 1
$1 == c
At the end:
$^R == c
$1 == c
Outside:
$^R == 1
$1 == c


I would also expect that there will be the "Inside" section for string "b: "
although it does not match, but the "Inside" section is (by my opinion) 
executed before perl guess it:

Inside:
$^R == 1
$1 == b
Inside:
$^R == 1
$1 == c
...

But this is probably not a bug.

  Thank you
  
    Tomas Telensky

[Please do not change anything below this line]
-----------------------------------------------------------------

---
Site configuration information for perl 5.00503:

Configured by root at Mon Aug 30 23:08:56 EDT 1999.

Summary of my perl5 (5.0 patchlevel 5 subversion 3) configuration:
  Platform:
    osname=linux, osvers=2.2.5-22smp, archname=i386-linux
    uname='linux porky.devel.redhat.com 2.2.5-22smp #1 smp wed jun 2 09:11:51 edt 1999 i686 unknown '
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=undef useperlio=undef d_sfio=undef
  Compiler:
    cc='cc', optimize='-O2', gccversion=egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)
    cppflags='-Dbool=char -DHAS_BOOL -I/usr/local/include'
    ccflags ='-Dbool=char -DHAS_BOOL -I/usr/local/include'
    stdchar='char', d_stdstdio=undef, usevfork=false
    intsize=4, longsize=4, ptrsize=4, doublesize=8
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
    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 -ldl -lm -lc -lposix -lcrypt
    libc=, 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 5.00503:
    /usr/lib/perl5/5.00503/i386-linux
    /usr/lib/perl5/5.00503
    /usr/lib/perl5/site_perl/5.005/i386-linux
    /usr/lib/perl5/site_perl/5.005
    .

---
Environment for perl 5.00503:
    HOME=/root
    LANG=en_US
    LANGUAGE (unset)
    LC_ALL=
    LC_CTYPE=cs_CZ
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=.:/root/bin:/usr/local/bin:/bin:/usr/bin:/usr/X11R6/bin:/sbin:/usr/sbin:/usr/local/sbin
    PERL_BADLANG (unset)
    SHELL=/bin/bash



Thread Next


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