From: Gurusamy Sarathy Date: Sat, 4 Dec 1999 21:11:51 +0000 (+0000) Subject: make eof() open ARGV if it isn't open already; also fixes bug X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=db7ec62399075c965a182629c9ca8ed4044fc594;p=p5sagit%2Fp5-mst-13.2.git make eof() open ARGV if it isn't open already; also fixes bug where eof() would operate on any last-read filehandle, not just ARGV p4raw-id: //depot/perl@4642 --- diff --git a/pp_sys.c b/pp_sys.c index 2f065ed..6599285 100644 --- a/pp_sys.c +++ b/pp_sys.c @@ -1703,10 +1703,28 @@ PP(pp_eof) GV *gv; MAGIC *mg; - if (MAXARG <= 0) - gv = PL_last_in_gv; + if (MAXARG <= 0) { + if (PL_op->op_flags & OPf_SPECIAL) { /* eof() */ + IO *io; + gv = PL_last_in_gv = PL_argvgv; + io = GvIO(gv); + if (io && !IoIFP(io)) { + if ((IoFLAGS(io) & IOf_START) && av_len(GvAVn(gv)) < 0) { + IoLINES(io) = 0; + IoFLAGS(io) &= ~IOf_START; + do_open(gv, "-", 1, FALSE, O_RDONLY, 0, Nullfp); + sv_setpvn(GvSV(gv), "-", 1); + SvSETMAGIC(GvSV(gv)); + } + else if (!nextargv(gv)) + RETPUSHYES; + } + } + else + gv = PL_last_in_gv; /* eof */ + } else - gv = PL_last_in_gv = (GV*)POPs; + gv = PL_last_in_gv = (GV*)POPs; /* eof(FH) */ if (gv && (mg = SvTIED_mg((SV*)gv, 'q'))) { PUSHMARK(SP);