проблемы вроде бы и нет
Как уже и говорилось ниже, вот пример:
package Test;
use overload (
'<>' => sub {
warn 'IterCall' . $_[0]->{iter};
return $_[0]->{iter}++ > 100 ? undef : 1;
}
);
sub new {
bless {}, Test;
}
package main;
my $test = new Test;
while (<$test>) {
}
02.02.2016, 23:04, "Sergey Aleynikov" <[email protected]>:
Добрый день,
overload говрит, что можно перегуржать <>
"Iteration
If <> is overloaded then the same implementation is used for both the
read-filehandle syntax <$var> and globbing syntax<${var}>.
"
но как??--
Точно так же, как и любой другой overload:
use 5.020;
use overload "<>" => sub {state $i=10; $i?--$i:undef};
my $f=bless {};
warn $_ while (<$f>);
Best regards,
Sergey Aleynikov
Moscow.pm mailing list
[email protected] | http://moscow.pm.org
-- Moscow.pm mailing list [email protected] | http://moscow.pm.org
