Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- use Modern::Perl 2010;
- use Data::Dumper;
- sub readFileNums {
- my ($fileName, $begin, $end) = @_;
- die if (defined $end and $begin > $end); ## можно реверз сделать
- my $cur = 1; ## см 1
- open (IN, $fileName) || die;
- while ($cur < $begin) { # как и тут
- <IN>;
- ++$cur;
- }
- sub {
- if (!wantarray) {
- return if defined $end and $cur == ($end + 1); # 1 тут реши сам с 0 или с 1
- ++$cur;
- <IN>;
- } else {
- my @text;
- if (defined $end) {
- while (defined (my $str = <IN>) and ($cur++ <= $end)) { ## как и тут
- push @text => $str;
- }
- } else {
- @text = <IN>;
- }
- @text;
- }
- }
- }
- my $it = readFileNums "test.txt", 2;
- while (my $t = $it->()) {
- print $t
- }
- print $it->();
Advertisement
Add Comment
Please, Sign In to add comment