Paul Johnson wrote:
> On Sat, Sep 21, 2002 at 10:05:50AM -0000, Smylers wrote:
>
> > Many Perl programs use C<$_> to mean
> > 'the current line'. 'A2' gives the Perl 6 syntax for this as:
> >
> > while $STDIN {
> >
> > Maybe somewhere in the middle of
> > it, it's necessary to have a C<for> loop iterating over something else.
> > ... I think it could surprise people if the variable holding 'the current
> > line' no longer holds that inside the C<for> or C<given>.
>
> I don't see what is different from perl 5.
Consider this Perl 5:
while (<>)
{
# ...
foreach my $fruit (qw<apple banana cherry>)
{
# ...
}
}
Inside the inner loop C<$_> still holds the current line. In the
equivalent Perl 6 syntax, insider the inner loop C<$_> will be an alias
of C<$fruit> and there wouldn't be any way of getting the current line.
> while $STDIN -> $line {
>
> or
>
> for $STDIN -> $line {
>
> as the input should be read lazily.
>
> As I wrote it $_ is the same as $line until some other construct claims
> the $_.
That solves the problem, since it answers the "But if it is" part of
this:
> > So I'm unconvinced that having an explicitly named topic always also
> > clobbering C<$_> is a good idea. But if it is, then we need a
> > simple syntax for reading file input lines into an explicitly named
> > topic.
Smylers