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

[ID 19991130.004] eof() Returns True Incorrectly Before Input Read.

Thread Next
Ralph Corderoy
November 30, 1999 10:22
[ID 19991130.004] eof() Returns True Incorrectly Before Input Read.
Message ID:


eof() (the <> magic version) returns true if no attempt to read from <>
has yet been made.

A simple test case (that doesn't illustrate why I want to do this) is

    #! /usr/local/bin/perl -w

    use strict;

    my $l;
    while (1) {
        eof() and print "eof\n";
        $l = <>;
        print "l='$l'\n";

Here's it running;  I've added comments.

    % ./p
    eof             # this is printed immediately.
    abc             # I type this
    l='abc          # this is OK
    eof             # I type ^D it prints eof;  again OK.
    Use of uninitialized value at ./p line 9, <> chunk 1.
    l=''            # it's a never ending loop so ^C to stop.

The behaviour once something has been read using <> is fine;  it's
before this the problem occurs.  If I have `eof() and last' instead or
use it as the `while ()' condition the body never gets executed.

I'm trying this now on a fairly old version, 5.00404, but I've just
logged into work and used 5.00502 with the same result.  Here's my
configuration at home for what it's worth.


Site configuration information for perl 5.00404:

Configured by root at Thu Sep 10 02:15:30 EDT 1998.

Summary of my perl5 (5.0 patchlevel 4 subversion 4) configuration:
    osname=linux, osvers=2.0.34, archname=i386-linux
    uname='linux 2.0.34 #1 thu may 7 10:17:44 edt 1998 i686 un
known '
    hint=recommended, useposix=true, d_sigaction=define
    bincompat3=y useperlio=undef d_sfio=undef
    cc='cc', optimize='-O2', gccversion=
    cppflags='-Dbool=char -DHAS_BOOL -I/usr/local/include'
    ccflags ='-Dbool=char -DHAS_BOOL -I/usr/local/include'
    stdchar='char', d_stdstdio=define, usevfork=false
    intsize=4, longsize=4, ptrsize=undef, doublesize=undef
    alignbytes=4, usemymalloc=n, prototype=define
  Linker and Libraries:
    ld='cc', ldflags =' -L/usr/local/lib'
    libpth=/usr/local/lib /lib /usr/lib
    libs=-lnsl -lndbm -lgdbm -ldb -ldl -lm -lc -lposix -lcrypt
    libc=, so=so
    useshrplib=false, libperl=libperl.a
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynamic'
    cccdlflags='-fpic', lddlflags='-shared -L/usr/local/lib'

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About