Dave Storrs writes:
: < 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").

Um, I don't think so.  What I wrote above was just a fancy trick with
straight Perl 5 overloading.  You could do that today.

I'd think that what you wrote would have to input one line from $STDIN
and then dup that line 4 times.  Either that, or because it's in list
context it inputs all the lines and duplicates each 4 times, just like

    @foo = @bar * 2;

maybe ought to multiply each element by two, at least the way some
numericists look at it.

Larry

Reply via email to