Front page | perl.perl6.language |
Postings from April 2006
=$fh vs *$fh
Thread Next
From:
Audrey Tang
Date:
April 22, 2006 02:55
Subject:
=$fh vs *$fh
Message ID:
4449FCDF.7050107@audreyt.org
During my S03 cleanup today, I noticed that because *$fh and **$fh
interpolates into the current argument list, it's always the same as
=$fh under list context. So I wrote this paragraph:
[Conjectural: File handles interpolates its lines into positional
arguments (e.g. to C<statement_control:<for>>), so we can make C<=$fh>
always return the next item, regardless of the context:
for *$fh -> $line { ... }; # read one line at a time
for **$fh -> $line { ... }; # read up all lines first
say(=$fh, =$fh, =$fh); # print three lines
]
However, this will mark a departure from the context-sensitive use of =$fh:
say =$fh; # prints everything
=$fh ~~ /.../; # reads just the first line
So, I wonder if the "=" operator can always just mean "return the next
thing", and leave the Perl5-esque context-sensitiveness to the
readline() function. I've written (scalar <FH>) many times in Perl 5
code, and I wonder if a reliably-scalar-context iterator can be a win
here... Thoughts?
Thanks,
Audrey
Thread Next
-
=$fh vs *$fh
by Audrey Tang