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 does not go out of scope #8281

Closed
p5pRT opened this issue Jan 13, 2006 · 4 comments
Closed

my-variable does not go out of scope #8281

p5pRT opened this issue Jan 13, 2006 · 4 comments

Comments

@p5pRT
Copy link

p5pRT commented Jan 13, 2006

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

Searchable as RT38224$

@p5pRT
Copy link
Author

p5pRT commented Jan 13, 2006

From fany@noris.net

Created by fany@noris.net

This is a bug report for perl from fany@​noris.net,
generated with the help of perlbug 1.35 running under perl v5.8.7.

-----------------------------------------------------------------

$ perl -Mstrict -le 'for (1..3) { { my $foo if 0; $foo .= $_; print $foo } }'
1
12
123

I would expect $foo to go out of scope at the end of the block
here---even if I had not used the additional inner block---, so
that each iteration of the foreach loop should start with $foo
being undef. However, due to the "if 0" modifier this does not
seem to happen.

BTW, the same behaviour can be reproduced using arrays of hashes.

If this is a feature, please explain it to me!

Regards,
fany

Perl Info

Flags:
    category=core
    severity=medium

Site configuration information for perl v5.8.7:

Configured by fany at Fri Jun  3 07:55:27 CEST 2005.

Summary of my perl5 (revision 5 version 8 subversion 7) configuration:
  Platform:
    osname=linux, osvers=2.6.11.4-20a-default, archname=i686-linux-64int-ld
    uname='linux fany 2.6.11.4-20a-default #1 wed mar 23 21:52:37 utc 2005 i686 athlon i386 gnulinux '
    config_args=''
    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=define use64bitall=undef uselongdouble=define
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='cc', ccflags ='-fno-strict-aliasing -pipe -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
    optimize='-O2 -march=athlon-xp',
    cppflags='-fno-strict-aliasing -pipe -I/usr/local/include'
    ccversion='', gccversion='3.3.5 20050117 (prerelease) (SUSE Linux)', 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='long double', nvsize=12, 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 -ldb -ldl -lm -lcrypt -lutil -lc
    perllibs=-lnsl -ldl -lm -lcrypt -lutil -lc
    libc=, so=so, useshrplib=false, libperl=libperl.a
    gnulibc_version='2.3.4'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E'
    cccdlflags='-fpic', lddlflags='-shared -L/usr/local/lib'

Locally applied patches:
    


@INC for perl v5.8.7:
    /usr/local/lib/perl5/5.8.7/i686-linux-64int-ld
    /usr/local/lib/perl5/5.8.7
    /usr/local/lib/perl5/site_perl/5.8.7/i686-linux-64int-ld
    /usr/local/lib/perl5/site_perl/5.8.7
    /usr/local/lib/perl5/site_perl
    .


Environment for perl v5.8.7:
    HOME=/home/fany
    LANG=de_DE@euro
    LANGUAGE (unset)
    LC_COLLATE=POSIX
    LD_LIBRARY_PATH=/usr/X11R6/lib
    LOGDIR (unset)
    PATH=/home/fany/bin:/usr/local/bin:/usr/bin:/usr/X11R6/bin:/bin:/usr/games:/opt/gnome/bin:/opt/kde3/bin:/usr/lib/mit/bin:/usr/lib/mit/sbin:/usr/NX/bin
    PERL_BADLANG (unset)
    SHELL=/bin/bash

@p5pRT
Copy link
Author

p5pRT commented Jan 13, 2006

From @smpeters

[fany@​noris.net - Fri Jan 13 05​:28​:24 2006]​:

This is a bug report for perl from fany@​noris.net,
generated with the help of perlbug 1.35 running under perl v5.8.7.

-----------------------------------------------------------------

$ perl -Mstrict -le 'for (1..3) { { my $foo if 0; $foo .= $_; print
$foo } }'
1
12
123

I would expect $foo to go out of scope at the end of the block
here---even if I had not used the additional inner block---, so
that each iteration of the foreach loop should start with $foo
being undef. However, due to the "if 0" modifier this does not
seem to happen.

BTW, the same behaviour can be reproduced using arrays of hashes.

If this is a feature, please explain it to me!

Regards,
fany

The "my $foo if 0" construct can be used to create something similar to
a static variable in C. You're right in thinking this is odd behavior,
which is why in bleadperl, it generates a warning.

./perl -Ilib -Mstrict -lwe 'for (1..3) { { my $foo if 0; $foo .= $_;
print $foo } }'
Deprecated use of my() in false conditional at -e line 1.
1
12
123

@p5pRT
Copy link
Author

p5pRT commented Jan 13, 2006

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

@p5pRT
Copy link
Author

p5pRT commented Jan 13, 2006

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