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

"my" variable is treated as a static variable under certain circumstance #8778

Closed
p5pRT opened this issue Feb 17, 2007 · 4 comments
Closed

Comments

@p5pRT
Copy link

p5pRT commented Feb 17, 2007

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

Searchable as RT41526$

@p5pRT
Copy link
Author

p5pRT commented Feb 17, 2007

From mmonopole-star@yahoo.com

Created by mmonopole-star@yahoo.com

"my" variable is treated as a static variable under certain circumstance.
Below is a sample code​:

=======================
#! /usr/local/bin/perl

use strict;
use warnings;

sub f($)
{
  my $arg = shift;

  my $x = 'a' if (0);

  $x ||= $arg;

  print "$x\n";
}

f('b');
f('c');

It should print out
b
c

Instead, it actually prints out
b
b

The value of $x is persisted across functional calls.

Perl Info

Flags:
    category=core
    severity=high

Site configuration information for perl v5.8.6:

Configured by mschilli at Fri Oct 20 17:26:31 EDT 2006.

Summary of my perl5 (revision 5 version 8 subversion 6) configuration:
  Platform:
    osname=linux, osvers=linux, archname=i686-linux-64int
    uname='linux pkgbuild6.corp.yahoo.com linux #1 fri oct 3 18:13:58 edt 2003 i686 '
    config_args='-d -e'
    hint=previous, useposix=true, d_sigaction=define
    usethreads=undef use5005threads=undef useithreads=undef usemultiplicity=undef
    useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
    use64bitint=define use64bitall=undef uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='gcc', ccflags ='-fno-strict-aliasing -pipe -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/include/gdbm',
    optimize='-O2',
    cppflags='-fno-strict-aliasing -pipe -I/usr/local/include -I/usr/include/gdbm -fno-strict-aliasing -pipe -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/include/gdbm'
    ccversion='', gccversion='3.2.3 20030502 (Red Hat Linux 3.2.3-20)', 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 -lgdbm -ldb -ldl -lm -lcrypt -lutil -lc
    perllibs=-lnsl -ldl -lm -lcrypt -lutil -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 -Wl,-R/home/y/lib -Wl,-R/usr/local/lib'
    cccdlflags='-fpic', lddlflags='-shared -L/usr/local/lib'

Locally applied patches:
    


@INC for perl v5.8.6:
    /home/y/lib
    /home/y/lib/perl5/5.8.6/i686-linux-64int
    /home/y/lib/perl5/5.8.6
    /home/y/lib/perl5
    /home/y/lib/perl5/site_perl/5.8.6/i686-linux-64int
    /home/y/lib/perl5/site_perl/5.8.6
    /home/y/lib/perl5/site_perl
    /home/hongj/projects/goto/src/perlsrc
    /home/hongj/projects/goto/lib/perllib
    /home/hongj/projects/goto/lib/perl5/5.8.6/i686-linux-64int
    /home/hongj/projects/goto/lib/perl5/5.8.6
    /home/hongj/projects/goto/lib/perl5
    /home/hongj/projects/goto/lib/perl5/site_perl/5.8.6/i686-linux-64int
    /home/hongj/projects/goto/lib/perl5/site_perl/5.8.6
    /home/hongj/projects/goto/lib/perl5/site_perl
    /home/y/lib
    /home/y/lib/perl5/5.8.6/i686-linux-64int
    /home/y/lib/perl5/5.8.6
    /home/y/lib/perl5
    /home/y/lib/perl5/site_perl/5.8.6/i686-linux-64int
    /home/y/lib/perl5/site_perl/5.8.6
    /home/y/lib/perl5/site_perl
    /home/hongj/projects/goto/src/perlsrc
    /home/hongj/projects/goto/lib/perllib
    /home/hongj/projects/goto/lib/perl5/5.8.6/i686-linux-64int
    /home/hongj/projects/goto/lib/perl5/5.8.6
    /home/hongj/projects/goto/lib/perl5
    /home/hongj/projects/goto/lib/perl5/site_perl/5.8.6/i686-linux-64int
    /home/hongj/projects/goto/lib/perl5/site_perl/5.8.6
    /home/hongj/projects/goto/lib/perl5/site_perl
    /home/hongj/projects/dmr/assoc/matching-pipeline/bin
    /usr/local/lib/jma/basisxs
    /usr/local/lib/jma/basisxs2
    /usr/local/lib/kma_20040128/krbasisxs
    /usr/local/lib/cma/xs
    /usr/local/lib/jma/basisxs
    /usr/local/lib/jma/basisxs2
    /usr/local/lib/kma_20040128/krbasisxs
    /usr/local/lib/cma/xs
    /home/y/lib/perl5/5.8/i686-linux-64int
    /home/y/lib/perl5/5.8
    /home/y/lib/perl5/site_perl/5.8/i686-linux-64int
    /home/y/lib/perl5/site_perl/5.8
    /home/y/lib/perl5/site_perl/5.8
    /home/y/lib/perl5/site_perl/5.8.6/i686-linux-64int
    /home/y/lib/perl5/site_perl/5.8.6
    /home/y/lib/perl5/site_perl
    /home/y/lib/perl5/5.8.6/i686-linux-64int
    /home/y/lib/perl5/5.8.6
    /home/y/lib/perl5/5.8.6/i686-linux-64int
    /home/y/lib/perl5/site_perl/5.8.6/i686-linux-64int
    /home/y/lib/perl5/site_perl/5.8.6
    /home/y/lib/perl5/site_perl/5.8.6/i686-linux-64int
    .


Environment for perl v5.8.6:
    HOME=/home/hongj
    LANG=en_US.UTF-8
    LANGUAGE (unset)
    LD_LIBRARY_PATH=/home/hongj/projects/goto/lib:/home/y/lib:/home/hongj/projects/goto/lib:/usr/local/lib:/usr/local/lib/jma/jni:/usr/local/lib/kma_20040128/jni:/usr/local/lib/jma/rosette:/usr/local/lib/cma:/usr/local/lib/cma/jni:/home/hongj/projects/goto/lib:/home/y/lib:/home/y/lib:/usr/local/lib:/home/hongj/projects/goto/lib:/usr/local/lib:/usr/local/lib/jma/jni:/usr/local/lib/kma_20040128/jni:/usr/local/lib/jma/rosette:/usr/local/lib/cma:/usr/local/lib/cma/jni:/home/hongj/projects/goto/lib:/home/y/lib:/home/y/lib:/home/y/libexec/weblogic/server/lib/linux:/home/hongj/projects/goto/thirdparty/wordnet1.7/lib:/home/hongj/projects/goto/thirdparty/rainbow/lib:/usr/local/oracle/product/9.2/lib:/usr/local/oracle/product/9.2/lib:/usr/local/oracle/product/9.2/lib
    LOGDIR (unset)
    PATH=/home/y/libexec/java/bin:/home/y/bin:/home/y/libexec/java/bin:/home/y/bin:/home/y/libexec/java/bin:/home/y/bin:/home/y/libexec/over_build_tools/wbin:/home/y/bin:/home/y/bin:/home/y/sbin:/usr/kerberos/bin:/usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin:/home/hongj/bin:/home/y/libexec/over_build_tools/bin:/usr/local/bin:/home/hongj/projects/goto/bin:/usr/local/javaware/bin:/usr/local/oracle/product/9.2/bin:/usr/local/inicis:/usr/local/oracle/product/9.2/bin:/usr/local/oracle/product/9.2/bin
    PERL5LIB=/home/y/lib:/home/y/lib/perl5:/home/y/lib/perl5/site_perl:/home/hongj/projects/goto/src/perlsrc:/home/hongj/projects/goto/lib/perllib:/home/hongj/projects/goto/lib/perl5:/home/hongj/projects/goto/lib/perl5/site_perl:/home/y/lib:/home/y/lib/perl5:/home/y/lib/perl5/site_perl:/home/hongj/projects/goto/src/perlsrc:/home/hongj/projects/goto/lib/perllib:/home/hongj/projects/goto/lib/perl5:/home/hongj/projects/goto/lib/perl5/site_perl:/home/hongj/projects/dmr/assoc/matching-pipeline/bin::/usr/local/lib/jma/basisxs:/usr/local/lib/jma/basisxs2:/usr/local/lib/kma_20040128/krbasisxs:/usr/local/lib/cma/xs:/usr/local/lib/jma/basisxs:/usr/local/lib/jma/basisxs2:/usr/local/lib/kma_20040128/krbasisxs:/usr/local/lib/cma/xs
    PERL_BADLANG (unset)
    SHELL=/bin/zsh

@p5pRT
Copy link
Author

p5pRT commented Feb 17, 2007

From @rgarcia

On 17/02/07, via RT John <perlbug-followup@​perl.org> wrote​:

"my" variable is treated as a static variable under certain circumstance.

Right. The construct "my $x if 0" will be deprecated in perl 5.10
(with a deprecation warning). Additionnally, a new keyword state()
will be introduced, to declare static variables.

@p5pRT
Copy link
Author

p5pRT commented Feb 17, 2007

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

@p5pRT
Copy link
Author

p5pRT commented Feb 17, 2007

@rgs - 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

2 participants