probando ejemplos

Uno de los ejemplos del tutorial:

(tomados de aca wget http://szabgab.com/talks/perl6/perl6_examples.tar.gz)

osvaldo@vostro:/opt/src/rakudo/examples/files$ cat read_file.p6 
#!/usr/bin/perl6
use v6;
my $filename = "examples/files/read_file.p6";
if (my $fh = open $filename, :r) {
    for $fh.readline -> $line {
        say $line;
    }
} else {
    say "Could not open '$filename'";
}

da este error:

osvaldo@vostro:/opt/src/rakudo$ ./perl6 examples/files/read_file.p6 
Method 'readline' not found for invocant of class 'IO'

Claro, la respuesta la encontre en irc:freenode#perl6

<osvaldo> hi everyone, i'm trying to run some examples and keep on getting this error message:

perl6 examples/files/read_file.p6

Method 'readline' not found for invocant of class 'IO'

any idea what might be happening?

<s1n> osvaldo: doesn't look like readline is in the spec anymore

<avar> I think it's .get now

ol .getline

<osvaldo> ah, ok, so the examples might just be too old then? s1n?

<-- jonathanturner has quit ()

<s1n> osvaldo: yes, the standard is a moving target

<osvaldo> s1n: thks!!

<JimmyZ> osvaldo: that mightp://tinyurl.com/oox6bm

en efecto, modifique el codigo del ejemplo

#!/usr/bin/perl6

use v6;

my $filename = "examples/files/read_file.p6";

if (my $fh = open $filename, :r) {

for $fh.get -> $line {

say $line;

}

} else {

say "Could not open '$filename'";

}

y funciona!

osvaldo@vostro:/opt/src/rakudo$ ./perl6 examples/files/read_file.p6

#!/usr/bin/perl6

pero claro, .get devuelve solo una linea hasta el input separator (newline en este caso). be not implemented .

<s1n> osvaldo: http://perlcabal.org/syn/S32/IO.html#IO%3A%3AReadable%3A%3AEncoded

<s1n> looks like avar is right

<lambdabot> Title: S32::IO, http://tinyurl.com/oox6bm

en efecto, modifique el codigo del ejemplo

#!/usr/bin/perl6

use v6;

my $filename = "examples/files/read_file.p6";

if (my $fh = open $filename, :r) {

for $fh.get -> $line {

say $line;

}

} else {

say "Could not open '$filename'";

}

y funciona!

osvaldo@vostro:/opt/src/rakudo$ ./perl6 examples/files/read_file.p6

#!/usr/bin/perl6

pero claro, .get devuelve solo una linea hasta el input separator (newline en este caso).

#!/usr/bin/perl6

use v6;

my $filename = "examples/files/read_file.p6";

if (my $fh = open $filename, :r) {

while !$fh.eof {

my $line = $fh.get;

say $line;

}

} else {

say "Could not open '$filename'";

}

(cortesia de victor)

Ahora si funciona como debe!