Subject: | Incorrect behavior with Readonly variables and for loops. |
The following code prints "no".
#!/usr/bin/perl -l
use strict;
use warnings;
use Readonly;
Readonly my $VAR => 'SEARCH';
# my $VAR = 'SEARCH'; # using this line will cause the code
# to print "yes"
foreach my $var ($VAR) {
print +($var eq $VAR) ? 'yes' : 'no';
}
The only reason I don't rate this as critical is that there is a workaround:
print +(lc $var eq lc $VAR) ? 'yes' : 'no';
Cheers,
Ovid
Kinetic $ perl -V
Summary of my perl5 (revision 5 version 8 subversion 7) configuration:
Platform:
osname=darwin, osvers=7.9.0, archname=darwin-2level
uname='darwin curtis-poes-computer.local 7.9.0 darwin kernel version 7.9.0: wed mar 30 20:11:17 pst 2005; root:xnuxnu-517.12.7.obj~1release_ppc power macintosh powerpc '
config_args='-de'
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 ='-fno-common -DPERL_DARWIN -no-cpp-precomp -fno-strict-aliasing -pipe -I/usr/local/include',
optimize='-Os',
cppflags='-no-cpp-precomp -fno-common -DPERL_DARWIN -no-cpp-precomp -fno-strict-aliasing -pipe -I/usr/local/include'
ccversion='', gccversion='3.3 20030304 (Apple Computer, Inc. build 1666)', gccosandvers=''
intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=4321
d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=8
ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
alignbytes=8, prototype=define
Linker and Libraries:
ld='env MACOSX_DEPLOYMENT_TARGET=10.3 cc', ldflags =' -L/usr/local/lib'
libpth=/usr/local/lib /usr/lib
libs=-ldbm -ldl -lm -lc
perllibs=-ldl -lm -lc
libc=/usr/lib/libc.dylib, so=dylib, useshrplib=false, libperl=libperl.a
gnulibc_version=''
Dynamic Linking:
dlsrc=dl_dyld.xs, dlext=bundle, d_dlsymun=undef, ccdlflags=' '
cccdlflags=' ', lddlflags=' -bundle -undefined dynamic_lookup -L/usr/local/lib'
Characteristics of this binary (from libperl):
Compile-time options: USE_LARGE_FILES
Built under darwin
Compiled at Jul 12 2005 12:10:35
%ENV:
PERL5LIB="/sw/lib/perl5:/sw/lib/perl5/darwin"
@INC:
/sw/lib/perl5
/sw/lib/perl5/darwin
/usr/local/lib/perl5/5.8.7/darwin-2level
/usr/local/lib/perl5/5.8.7
/usr/local/lib/perl5/site_perl/5.8.7/darwin-2level
/usr/local/lib/perl5/site_perl/5.8.7
/usr/local/lib/perl5/site_perl