develooper Front page | perl.perl6.language | Postings from April 2006

=$fh vs *$fh

Thread Next
Audrey Tang
April 22, 2006 02:55
=$fh vs *$fh
Message ID:
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?


Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About