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

good, bad, evil and naughty: 4 ways to close ARGV inside a while(<>) #5247

Open
p5pRT opened this issue Mar 11, 2002 · 2 comments
Open

good, bad, evil and naughty: 4 ways to close ARGV inside a while(<>) #5247

p5pRT opened this issue Mar 11, 2002 · 2 comments

Comments

@p5pRT
Copy link

p5pRT commented Mar 11, 2002

Migrated from rt.perl.org#8829 (status was 'stalled')

Searchable as RT8829$

@p5pRT
Copy link
Author

p5pRT commented Mar 11, 2002

From tagunov@motor.ru

This is a bug report for perl from "Anton Tagunov" <tagunov@​motor.ru>,
generated with the help of perlbug 1.33 running under perl v5.7.3.


Hello, all! Trying to figure out if closing ARGV inside while(<>)
could close STDIN have found that the following four samples
work all differently (the names of the testcases are arbitrary,
I do not think one behaviour to be good while other bad, I do
not know which one is preferable :-)

good.pl----------
use strict; use warnings;
#error​: readline() on closed filehandle ZZZ at good.pl line ..
@​ARGV = ( '<'.$0 );
unshift(@​ARGV, '-') unless @​ARGV;
while ($ARGV = shift @​ARGV) {
  open(ZZZ, $ARGV);
  while (<ZZZ>) {
  close ZZZ;
  print '.',$_;
  }
}

bad.pl------------
use strict; use warnings;
#prints one line and bails out
@​ARGV = ( '<'.$0 );
while (<>) {
  close ARGV;
  print '.',$_;
}

evil.pl------------
use strict; use warnings;
#prints _two_ lines
open STDIN, $0;
@​ARGV = ( '-' );
unshift(@​ARGV, '-') unless @​ARGV;
while ($ARGV = shift @​ARGV) {
  open(ARGV, $ARGV);
  while (<ARGV>) {
  close ARGV;
  print '.',$_;
  }
}

naughty.pl----------
use strict; use warnings;
# reads both @​ARGV and STDIN,
#
# related to
#
# '[ID 20020222.011]
# while(<>){close ARGV if eof; eof();}
# produces unexpected behavior'
#
# ?
open STDIN,'<'.$0;
@​ARGV = ( '<'.$0 );
unshift(@​ARGV, '-') unless @​ARGV;
while ($ARGV = shift @​ARGV) {
  open(ARGV, $ARGV);
  while (<ARGV>) {
  close ARGV;
  print '.',$_;
  }
}

Uff! What a fun, gentlemen! Do you like diversity? :-)

- Anton



Flags​:
  category=core
  severity=low


Site configuration information for perl v5.7.3​:

Configured by anthony at Wed Mar 6 00​:02​:07 2002.

Summary of my perl5 (revision 5 undef) configuration​:
  Platform​:
  osname=MSWin32, osvers=4.0, archname=MSWin32-x86-multi-thread
  uname=''
  config_args='undef'
  hint=recommended, useposix=true, d_sigaction=undef
  usethreads=undef use5005threads=undef useithreads=define usemultiplicity=define
  useperlio=define d_sfio=undef uselargefiles=undef usesocks=undef
  use64bitint=undef use64bitall=undef uselongdouble=undef
  usemymalloc=n, bincompat5005=undef
  Compiler​:
  cc='cl', ccflags ='-nologo -Gf -W3 -O1 -MD -DNDEBUG -DWIN32 -D_CONSOLE -DNO_STRICT -DPERL_IMPLICIT_CONTEXT
-DPERL_IMPLICIT_SYS
-DUSE_PERLIO -DPERL_MSVCRT_READFIX',
  optimize='-O1 -MD -DNDEBUG',
  cppflags='-DWIN32'
  ccversion='undef', gccversion='', gccosandvers='undef'
  intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
  d_longlong=undef, longlongsize=8, d_longdbl=define, longdblsize=10
  ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=4
  alignbytes=8, prototype=define
  Linker and Libraries​:
  ld='link', ldflags ='-nologo -nodefaultlib -release -libpath​:"c​:\perl5047\lib\CORE" -machine​:x86'
  libpth=e​:\apps\ds40\VC\lib
  libs= oldnames.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib
oleaut32.lib
netapi32.lib uuid.lib wsock32.lib mpr.lib winmm.lib version.lib odbc32.lib odbccp32.lib msvcrt.lib
  perllibs=undef
  libc=msvcrt.lib, so=dll, useshrplib=yes, libperl=perl57.lib
  Dynamic Linking​:
  dlsrc=dl_win32.xs, dlext=dll, d_dlsymun=undef, ccdlflags=' '
  cccdlflags=' ', lddlflags='-dll -nologo -nodefaultlib -release -libpath​:"c​:\perl5047\lib\CORE" -machine​:x86'

Locally applied patches​:
  DEVEL15046


@​INC for perl v5.7.3​:
  c​:/perl15046/lib
  c​:/perl15046/site/lib
  .


Environment for perl v5.7.3​:
  HOME=C​:\
  LANG (unset)
  LANGUAGE (unset)
  LC_ALL=EN_US
  LD_LIBRARY_PATH (unset)
  LOGDIR (unset)
  PATH=E​:\apps\ibm\vaj\eab\bin;C​:\usr\local\bin\;e​:\Program
Files\ibm\gsk5\lib;E​:\APPS\ROSE\RATION1\NUTCROOT\bin;E​:\APPS\ROSE\RATION1\NUTCROOT\bin\x11;E​:\APPS\ROSE\RATION~1\NUTCROOT\mksnt;e​:\java\sun\java131\bin;e​:\apps\vbroker\jre\Bin;e​:\apps\vbroker\Bin;C​:\WINNT\system32;C​:\WINNT;c​:\util;E​:\apps\CacheSys\Bin;C​:\Program
Files\rksupport;C​:\WINNT\ton\bin;E​:\apps\rose\common;E​:\apps\rose\Rational
Test;E​:\apps\borland\delphi\Bin;E​:\apps\borland\delphi\Projects\Bpl;E​:\apps\ibm\IBM\IMNNQ;E​:\apps\ibm\db2p\BIN;E​:\apps\ibm\db2p\FUNCTION;E​:\apps\ibm\db2p\SAMPLES\REPL;E​:\apps\ibm\db2p\HELP;e​:\apps\ibm\websphere\bin
  PERL_BADLANG (unset)
  SHELL (unset)

@p5pRT
Copy link
Author

p5pRT commented May 23, 2010

@chorny - Status changed from 'open' to 'stalled'

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