YAP6 Operator: Iterate Operator

by Adriano Ferreira

Another article of the series "Yet Another Perl 6 Operator"

If you are wondering how processing the lines of a file will look in Perl 6, the answer is something like this:

my $h = open '<', $filename;

for =$h {

(Yes, we need error handling yet. I just ommitted the details for brevity.)


2007-12-24 14:45:48
These "YAP6 Operator" articles are damaging to the Perl community. They are talking about operators which are not available yet, so they are just diluting interest in Perl. When Perl 6 finally releases an alpha release, how exactly do you plan to build any interest after these tedious articles?
2007-12-25 06:51:53
Merry Christmas Tom, I completely disagree with you. We need to be looking forward, and we need to get people into the mindset that this is going to happen, potentially soon.
2008-01-20 05:33:26

I totally and emphatically disagree with you.

2008-01-20 10:15:42
my $h = open '<', $filename;

should be

my $h = open $filename, :r;

Ed Avis
2008-01-27 07:33:58
So, how do you get error handling? IMHO it's a bad idea to show code examples which leave out error checking, they give a misleading impression.

Surely Perl 6 has some shorter, safer, and more standardized alternative to always writing

open my $fh, '<', $filename or die "could not open $filename for reading: $!";