On Thu, 10 May 2001, Larry Wall wrote:
> Dave Storrs writes:
> : 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.
Hmmm...I see your point, but I think it depends on what you see as
the operatee that 'x' is operating on. If it's the string(s) produced by
<>, then you're certainly right. But if it is the act of iterating
itself, then I think my suggestion is still valid. And yes, I realize
that the current behavior is always to act on the string, not the act of
calling the function that produced the string, or whatever. I just think
that we could extend 'x' to have a general repetition meaning. Imagine
the following:
our $a = 0;
our $baz = 'jaz';
sub blah {
$a++;
return 'Hi';
}
$foo = 'bar' x 2; # $foo => 'barbar'
$foo = $baz x 2; # $foo => 'jazjaz'
$foo = blah() x 2; # blah() called twice,
# $foo = 'Hi', $a = 2
$foo = join '', (blah() x 2) # blah() called twice,
# $foo => 'HiHi', $a = 4
$foo = <$STDIN> x 2; # read two lines, discard first,
# stick second into $foo
@foo = <$STDIN> x 2; # read two lines, stick into @foo
Dave