>From S04:
It is possible to write

    while =$*IN -> $line {...}

But it won't do what you expect, because unary = does a slurp in
scalar context, so $line will contain the entire file.
----------------------------------------------------------------

So I expected this function to slurp the whole file, but in Pugs
it does not; it reads only the first line:

sub slurp_file (Str $fname) returns Str {
    my $fh = open($fname) or die("open '$fname' failed");
    my $s = =$fh;
    $fh.close();
    return $s;
}

This function does appear to successfully slurp in Pugs:

sub slurp_file (Str $fname) returns Str {
    my $fh = open($fname) or die("open '$fname' failed");
    my $s;
    for =$fh  -> $line { $s ~= $line }
    $fh.close();
    return $s;
}

What is the best way in Perl6/Pugs to slurp a file?

/-\


Find local movie times and trailers on Yahoo! Movies.
http://au.movies.yahoo.com

Reply via email to