develooper Front page | perl.perl5.porters | Postings from November 1999

[ID 19991126.002] overwriting with scalar $_ using foreach overarray and inner wh ile loop

Thread Next
From:
Koester, Bernd
Date:
November 26, 1999 06:38
Subject:
[ID 19991126.002] overwriting with scalar $_ using foreach overarray and inner wh ile loop
Message ID:
A11512FA21D5D111A04800805F85B92403BBC77D@s70a91.otn.lm.dasa.de
This is a bug report for perl from bernd.koester@m.dasa.de,
generated with the help of perlbug 1.19 running under perl 5.00503.

-----------------------------------------------------------------
[Please enter your report here]
Using default scalar $_ (implicit) in an foreach loop over an array
and having an inner while loop reading a file we noticed that perl is 
overwriting the scalar of the outer loop inserting read lines 
from the file into the array.

my @array=(1,2,3);
foreach (@array) {
   open FILE, "<test";
   while <FILE> {
      ...
      }
   close FILE;
   }

 
FILE contains just one character (a).
After this procedure @array contains (a,a,a)!
Best regards, 

Bernd and Dirk

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

---
Site configuration information for perl 5.00503:

Configured by root at Mon May 10 10:54:22 MET DST 1999.

Summary of my perl5 (5.0 patchlevel 5 subversion 3) configuration:
  Platform:
    osname=solaris, osvers=2.5, archname=sun4-solaris
    uname='sunos sunny2 5.5 generic sun4m sparc sun4m '
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=undef useperlio=undef d_sfio=undef
  Compiler:
    cc='cc', optimize='-O', gccversion=
    cppflags='-I/usr/local/include'
    ccflags ='-I/usr/local/include'
    stdchar='unsigned char', d_stdstdio=define, usevfork=false
    intsize=4, longsize=4, ptrsize=4, doublesize=8
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
    alignbytes=8, usemymalloc=y, prototype=define
  Linker and Libraries:
    ld='cc', ldflags =' -L/usr/local/lib'
    libpth=/usr/local/lib /lib /usr/lib /usr/ccs/lib
    libs=-lsocket -lnsl -ldl -lm -lc -lcrypt
    libc=/lib/libc.so, so=so, useshrplib=false, libperl=libperl.a
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags=' '
    cccdlflags='-KPIC', lddlflags='-G -L/usr/local/lib'


---
@INC for perl 5.00503:
	/usr/local/lib/perl5/5.00503/sun4-solaris
	/usr/local/lib/perl5/5.00503
	/usr/local/lib/perl5/site_perl/5.005/sun4-solaris
	/usr/local/lib/perl5/site_perl/5.005
	.

---
Environment for perl 5.00503:
    HOME=/usr/users/sunny6/ko26619
    LANG (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
 
PATH=/usr/users/sunny6/ko26619:/usr/users/sunny6/ko26619/tools:/disks/disk1/
oracle/733/bin:/usr/users/sunny6/csdb/v0.2/lib:/disks/disk1/adobe/Acrobat3/b
in:/usr/users/sunny6/ko26619:/otn/sunny11/d7/a701/adept/bin:/otn/sunny11/d7/
a701/adept/bin/sun4r5:/otn/sunny11/d7/a701/adept/bin/sun4r5/dasa:/otn/sunny1
1/d7/a701/adept/lib/sun4r5:/usr/bin/X11:/otn/sunny11/d7/a701/csdb/lib:/otn/s
unny11/d7/csdb/idb_com:/opt/bin:/bin:/usr/bin:/usr/ccs/bin:/usr/local/bin:/u
sr/local:/usr/openwin/bin:/usr/new:/usr/hosts:/opt/SUNWspro/bin:/usr/users/s
unny6/ko26619:/otn/sunny11/d7/o40l/csdb/lib:/otn/sunny11/d7/o40l/omle40/bin:
/usr/users/sunny6/ko26619:/usr/users/sunny6/ko26619/tools:/disks/disk1/oracl
e/733/bin:/usr/users/sunny6/csdb/v0.2/lib:/disks/disk1/adobe/Acrobat3/bin:/u
sr/users/sunny6/ko26619:/otn/sunny11/d7/a701/adept/bin:/otn/sunny11/d7/a701/
adept/bin/sun4r5:/otn/sunny11/d7/a701/adept/bin/sun4r5/dasa:/otn/sunny11/d7/
a701/adept/lib/sun4r5:/usr/bin/X11:/otn/sunny11/d7/a701/csdb/lib:/otn/sunny1
1/d7/csdb/idb_com:/opt/bin:/bin:/usr/bin:/usr/ccs/bin:/usr/local/bin:/usr/lo
cal:/usr/openwin/bin:/usr/new:/usr/hosts:/opt/SUNWspro/bin:/usr/users/sunny6
/ko26619:/otn/sunny11/d7/o40l/csdb/lib:/otn/sunny11/d7/o40l/omle40/bin:/usr/
bin::/otn/sunny11/d7/o40l/omni40/bin:/otn/sunny11/d7/o40l/flexlm-5.12a/bin:/
usr/local/bin/netscape:.:/otn/sunny11/d7/o40l/omni40/bin:/otn/sunny11/d7/o40
l/flexlm-5.12a/bin:/usr/local/bin/netscape:.
    PERL=/disks/disk1/csdb/www/v0.2/csdb-perl
    PERL_BADLANG (unset)
    SHELL=/usr/bin/ksh




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