develooper Front page | perl.perl5.porters | Postings from August 2003

[perl #23624] scoping of @+/@- when useed with tie()

Thread Next
From:
perlbug-followup
Date:
August 28, 2003 09:39
Subject:
[perl #23624] scoping of @+/@- when useed with tie()
Message ID:
rt-23624-63850.1.83241506088009@rt.perl.org
# New Ticket Created by  tassilo.parseval@post.rwth-aachen.de 
# Please include the string:  [perl #23624]
# in the subject line of all future correspondence about this issue. 
# <URL: http://rt.perl.org/rt2/Ticket/Display.html?id=23624 >



This is a bug report for perl from tassilo.parseval@post.rwth-aachen.de,
generated with the help of perlbug 1.34 running under perl v5.8.0.


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

Hi,

there is something very odd going on when trying to emulate $`, $' and $&
through tied hashes. See this code:

    #! /usr/bin/perl -w

    package Tie::Prematch;
    sub TIEHASH { bless \my $dummy => __PACKAGE__ }
    sub FETCH   { return substr $_[1], 0, $-[0] }

    package main;

    tie my %pre, 'Tie::Prematch';
    my $foo = "foobar";
    $foo =~ s/.ob/$pre{ $foo }/;
    print $foo, "\n";

    $foo = "foobar";
    $foo =~ s/.ob/tied(%pre)->FETCH($foo)/e;
    print $foo, "\n";

    tie %-, 'Tie::Prematch';
    $foo = "foobar";
    $foo =~ s/.ob/$-{$foo}/;
    print $foo;
    __END__
    Use of uninitialized value in substr at bug.pl line 5.
    far
    ffar
    ffar

According to my knowledge, @- and @+ should be dynamically scoped so it's
obvious that they still have their values in Tie::Prematch::FETCH() when doing 

    $foo =~ s/.ob/tied(%pre)->FETCH($foo)/e;

But they somehow loose them when doing

    $foo =~ s/.ob/$pre{ $foo }/;

even though it should be functionally identical.

It's even stranger: as the third example in the above shows, it works when
I tie one of the truely global symbols (%- in this case). It turns out that
this kind of tying behaves normally with punctuation variables but fails
with lexicals and package variables.

This bug is present in at least 5.6.1, 5.8.0 and 5.8.1RC4.

Tassilo

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

Configured by root at Tue Feb 25 16:06:57 Local time zone must be set--see zic manual page 2003.

Summary of my perl5 (revision 5.0 version 8 subversion 0) configuration:
  Platform:
    osname=linux, osvers=2.4.20, archname=i686-linux
    uname='linux ethan 2.4.20 #2 mon dec 2 14:26:23 cet 2002 i686 unknown '
    config_args='-ds -e -Dprefix=/usr -Dccflags= -O3 -march=athlon'
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=undef use5005threads=undef useithreads=undef usemultiplicity=undef
    useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
    use64bitint=undef use64bitall=undef uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='cc', ccflags ='-O3 -march=athlon -fno-strict-aliasing -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
    optimize='-O2',
    cppflags='-O3 -march=athlon -fno-strict-aliasing'
    ccversion='', gccversion='3.2', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
    alignbytes=4, prototype=define
  Linker and Libraries:
    ld='cc', ldflags =' -L/usr/local/lib'
    libpth=/usr/local/lib /lib /usr/lib
    libs=-lnsl -ldl -lm -lc -lcrypt -lutil
    perllibs=-lnsl -ldl -lm -lc -lcrypt -lutil
    libc=/lib/libc-2.2.5.so, so=so, useshrplib=false, libperl=libperl.a
    gnulibc_version='2.2.5'
  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 v5.8.0:
    /usr/lib/perl5/5.8.0/i686-linux
    /usr/lib/perl5/5.8.0
    /usr/lib/perl5/site_perl/5.8.0/i686-linux
    /usr/lib/perl5/site_perl/5.8.0
    /usr/lib/perl5/site_perl
    .

---
Environment for perl v5.8.0:
    HOME=/home/ethan
    LANG=C
    LANGUAGE (unset)
    LC_CTYPE=de_DE@euro
    LD_LIBRARY_PATH=:/usr/local/j2sdk1.4.0/jre/lib/i386:/usr/local/pwlib/lib
    LOGDIR (unset)
    PATH=/usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin:/usr/games:/usr/local/j2re1.4.1/bin
    PERLDOC_PAGER=/bin/less -isR
    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