Created
August 21, 2010 14:53
-
-
Save colomon/542417 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class LinesIter is Iterator { | |
has $!filehandle; | |
has $!value; | |
method new($fh) { | |
my $result = self.CREATE; | |
pir::setattribute__vPsP($result, '$!filehandle', $fh); | |
$result; | |
} | |
method infinite() { False } | |
method reify() { | |
unless $!value.defined { | |
$!value := pir::new('Parcel'); | |
my $line = $!filehandle.get; | |
if $line.defined { | |
pir::push($!value, $line); | |
$line = $!filehandle.get; | |
if $line.defined { | |
pir::push($!value, $line); | |
$line = $!filehandle.get; | |
if $line.defined { | |
pir::push($!value, $line); | |
pir::push($!value, LinesIter.new($!filehandle)); | |
} | |
} | |
} | |
} | |
$!value; | |
} | |
} | |
my $count = 0; | |
for LinesIter.new($*IN).list { | |
$count++; | |
} | |
say :$count.perl; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment