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

Re: [PATCH] readline() with no FILEHANDLE

Thread Previous | Thread Next
From:
Rafael Garcia-Suarez
Date:
March 7, 2002 02:45
Subject:
Re: [PATCH] readline() with no FILEHANDLE
Message ID:
20020307115022.A887@rafael
On 2002.03.06 23:10 Yitzchak Scott-Thoennes wrote:
> I become more and more convinced this is broken as is.
> 
> For instance:
> ~/bleadperl/perl $perl -wle'open FOO, "<a" and readline FOO'
> Name "main::FOO" used only once: possible typo at -e line 1.

"readline FOO" is currently equivalent to "readline 'FOO'", so
FOO is used only once, in open().

(BTW perlfunc says that the correct syntax is "readline *FOO",
and does not mention readline without an argument.)

The problem as I see it :

The optimizations on the op tree for the <> operator are done in toke.c.
(e.g. providing the implicit ARGV argument, etc. Look at function
toke.c:S_scan_inputsymbol).

These do not occur with the readline() syntax. But both happen to produce
the same op, codenamed readline. Thus the optree for readline(FH) is broken.

Examples :

  $ bleadperl -MO=Concise -ereadline
  4  <@> leave[t1] vKP/REFC ->(end)
  1     <0> enter ->2
  2     <;> nextstate(main 1 -e:1) v ->3
  3     <0> readline[t1] v ->4			<-------no child !

  $ bleadperl -MO=Concise -e'<>'    
  5  <@> leave[t1] vKP/REFC ->(end)
  1     <0> enter ->2
  2     <;> nextstate(main 1 -e:1) v ->3
  4     <1> readline[t1] vK/1 ->5
  3        <$> gv(*ARGV) s ->4

  $ bleadperl -MO=Concise -e 'readline FOO'
  5  <@> leave[t1] vKP/REFC ->(end)
  1     <0> enter ->2
  2     <;> nextstate(main 1 -e:1) v ->3
  4     <1> readline[t1] vK/1 ->5
  3        <$> const(PV "FOO") s/BARE ->4 <-----bareword string value!

  $ bleadperl -MO=Concise -e '<FOO>'
  5  <@> leave[t1] vKP/REFC ->(end)
  1     <0> enter ->2
  2     <;> nextstate(main 1 -e:1) v ->3
  4     <1> readline[t1] vK/1 ->5
  3        <$> gv(*FOO) s ->4

So your patch looks like it corrects some of the problems (I haven't tried
it yet), but it won't add a missing ARGV to readline(). Minor problem, if
you forbid the no-arg syntax.

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