develooper Front page | perl.perl6.language | Postings from May 2001

Apoc2 - <STDIN> concerns

Thread Previous | Thread Next
From:
Nathan Wiger
Date:
May 4, 2001 17:21
Subject:
Apoc2 - <STDIN> concerns
Message ID:
20010504164207.W15504@west.sun.com
There's a lot of good stuff in Apoc2, but I did have at least one
semantic concern. In it, there's this proposal:

: There is likely to be no need for an explicit input operator in Perl 6,
: and I want the angles for something else. I/O handles are a subclass of
: iterators, and I think general iterator variables will serve the purpose
: formerly served by the input operator, particularly since they can
: be made to do the right Thing in context. For instance, to read from
: standard input, it will suffice to say
:
:      while ($STDIN) { ... }

I'm wondering what this will do?

   $thingy = $STDIN;

This seems to have two possibilities:

   1. Make a copy of $STDIN

   2. Read a line from $STDIN

To be semantically coherent, it seems that the first one should be the way
it works, like with other variables. That is:

   $FILE = open "</etc/motd";

   $DUP = $FILE;        # dup input stream
   $line = <$FILE>;     # or $FILE.readline

This gives you some niceties:

   $STDERR = $STDOUT;   # redirect

Or, it could be that simple assignment instead grabs the iterator:

   $line = $FILE;       # grabs $FILE.readline, which is next line
   $DUP = $FILE.dup;    # must call dup() to duplicate filehandle

If it's the latter, then <> is free. However, if it's the former then
we'll still need them. Personally, that latter one scares me a little,
but I'm open-minded.

-Nate


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