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

Re: Apoc2 - <STDIN> concerns

From:
Dave Storrs
Date:
May 10, 2001 15:33
Subject:
Re: Apoc2 - <STDIN> concerns
Message ID:
Pine.BSF.4.21.0105101525510.93264-100000@megazone23.bigpanda.com

< QUOTE LARRY >
Dave Storrs writes:
:       You know, it would be really cool if you specify the number of
: lines you wanted like so:
: 
:       <$STDIN                 # One line
:       *<$STDIN                # All available lines
:       *4<$STDIN               # Next 4 lines
: 
: Or even:
: 
:       *$num_lines<$STDIN      # Numifies $num_lines, gets that many
:       *int rand(6)<$STDIN     # Gets 0-5 lines
:       *&mySub($bar)<$STDIN    # mySub returns num, gets that many

Given appropriate overloading on the iterator object:

    @foo = $STDIN * 4;

Larry

< END QUOTE>



Actually, on more reflection, I'm going to side with the people who say
that the single-character version is not an improvement, and that we
should stick with <>.  Also, I'd prefer to use the 'x' operator for
specifying multiples:

	@foo = <$STDIN> x 4;
	@foo = <$STDIN> x &mySub;
	
The parallel with "$foo = 'bar'x2;", where bar is simply repeated twice,
is obvious:  '<$STDIN' iterates the, uh, iterator, and repeating that
operation iterates it multiple times.  It even reads nicely "Fetch a line
from STDIN times four" (or, more idiomatically, "...four times").

			Dave




nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About