develooper Front page | perl.perl5.porters | Postings from October 2003

open()ing a directory for reading

From:
Torsten Foertsch
Date:
October 31, 2003 03:39
Subject:
open()ing a directory for reading
Message ID:
200310311237.56905.torsten.foertsch@gmx.net
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Is it a bug or a feature?

# perl -e 'open F, "/" and defined(scalar <F>) and print "ok\n"; print "$!\n"'
Is a directory

but

# perl -e 'undef $/;open F, "/" and defined(scalar <F>) and print "ok\n"; 
print "$!\n"'
ok
Is a directory


Under Linux read(2) returns EISDIR if the file descriptor refers to a 
directory, i.e. it is an error.

perlop states:
       In scalar context, evaluating a filehandle in angle brackĀ­
       ets yields the next line from that file (the newline, if
       any, included), or "undef" at end-of-file or on error.
       When $/ is set to "undef" (sometimes known as file-slurp
       mode) and the file is empty, it returns '' the first time,
       followed by "undef" subsequently.

I think even in the second case C<< scalar <F> >> should return C<undef>, 
shouldn't it?

Torsten

- ------------------------------------------------------------------
# perl -V
Summary of my perl5 (revision 5.0 version 8 subversion 0) configuration:
  Platform:
    osname=linux, osvers=2.4.19, archname=i586-linux-thread-multi
    uname='linux bloembergen 2.4.19 #1 mon apr 15 08:57:26 gmt 2002 i686 
unknown '
    config_args='-ds -e -Dprefix=/usr -Dusethreads -Di_db -Di_dbm -Di_ndbm 
- -Di_gdbm -Duseshrplib=true'
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=define use5005threads=undef useithreads=define 
usemultiplicity=define
    useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
    use64bitint=undef use64bitall=undef uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='cc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing 
- -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
    optimize='-O3 --pipe',
    cppflags='-D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing'
    ccversion='', gccversion='3.2', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', 
lseeksize=8
    alignbytes=4, prototype=define
  Linker and Libraries:
    ld='cc', ldflags =''
    libpth=/lib /usr/lib /usr/local/lib
    libs=-lnsl -ldl -lm -lpthread -lc -lcrypt -lutil
    perllibs=-lnsl -ldl -lm -lpthread -lc -lcrypt -lutil
    libc=, so=so, useshrplib=true, libperl=libperl.so
    gnulibc_version='2.2.5'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynamic 
- -Wl,-rpath,/usr/lib/perl5/5.8.0/i586-linux-thread-multi/CORE'
    cccdlflags='-fPIC', lddlflags='-shared'


Characteristics of this binary (from libperl): 
  Compile-time options: MULTIPLICITY USE_ITHREADS USE_LARGE_FILES 
PERL_IMPLICIT_CONTEXT
  Built under linux
  Compiled at Sep  9 2002 18:13:56
  @INC:
    /usr/lib/perl5/5.8.0/i586-linux-thread-multi
    /usr/lib/perl5/5.8.0
    /usr/lib/perl5/site_perl/5.8.0/i586-linux-thread-multi
    /usr/lib/perl5/site_perl/5.8.0
    /usr/lib/perl5/site_perl
    .
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)

iD8DBQE/okmUwicyCTir8T4RAjjeAJ40MZi3x3abzhQDe8oUoVpFhu5oQgCgssKW
u6/l6Zxc2JJNhkGXvmvXyPA=
=axI4
-----END PGP SIGNATURE-----



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About