develooper Front page | perl.perl5.porters | Postings from March 2002

[Related issues?] [PATCH] readline() with no FILEHANDLE, [ID 20020222.011]

Thread Previous | Thread Next
From:
Anton Tagunov
Date:
March 7, 2002 18:28
Subject:
[Related issues?] [PATCH] readline() with no FILEHANDLE, [ID 20020222.011]
Message ID:
3949699413.20020308052457@newmail.ru
Guys, you look experts at this :-)

RGS> IHMO, the right way to fix this is
RGS> - to add a private op flag to OP_READLINE to indicate
RGS>   that the readline() syntax was used instead of <>.
RGS> - to change ck_null to ck_fun in opcode.pl as you did.
RGS> - to modify ck_fun to check for this flag, and do nothing
RGS>   if it's not present.

RGS> Also, the op corresponding to readline($fh) should have an OPf_SPECIAL
RGS> flag, just like <$fh> does.

RGS> And while we're at it, make readline() without arguments equivalent
RGS> to readline(*ARGV).

Once you're looking at all these things, you probably could have a
look at the following troubles (item 1 is like a value of 100
2 and 3 have a value around 7 to me) :

1) ----[ID 20020222.011])-----

while(<>){ print $.,'. ',$_; close ARGV if eof;    eof();        }

is equivalent to-----

my $f;
do{
    $f=0;
    while(<>){
        $f = 1;
        print $.,'. ',$_;
        if (eof){
            close ARGV;
        }
    }
}while($f);

-------------------------------------------------------------------

Looks like eof() after close ARGV somehow resets the while(<>) operator
and the latter starts all over again.
Since by that moment the @ARGV is empty, it starts reading '-'..

If only the eof() status that has been detected in the call to eof()
could be saved in the while(<>), so that the loop would bail out...


2) ----[Failed to report via perlbug@perl.org, the server does not
confirm the receipt of my message, so no bug id]-----

The tests are in the attached.
The thing is all bout doing close ARGV; inside a while(<>) or its
hand-made analog. Quite puzzling to me, but of a moderate importance.

3) ----question on open FH, '-' -------

   open FH, '-' behaves neither
   like '<&=STDIN' nor like '<=' should behave:

open STDIN,'<'.$0;
open V,'-';
close V;
while(<STDIN>){print}; #prints the source

open STDIN,'<'.$0;
open V,'-';
close STDIN;
while(<V>){print}; #does not

Is this as expected? Is this documented anywhere?

- Regares, with _great respect_ :) and TIA

- Anton

Thread Previous | 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