The error is:more last_ten.pl #! /usr/bin/perl -w use strict; use File::ReadBackwards; use diagnostics; open my $read_log_file, '<', '/home/jay/my_perl_programs/log.txt' or d +ie $!; open my $output_file, '>', '/home/jay/my_perl_programs/log_output.txt' + or die $!; my @log_last_ten; my $log_backwards = File::ReadBackwards->new($read_log_file) or die $! +; while (defined(my $log_lines = $log_backwards->readline)) { unshift @log_last_ten, $log_lines; last if @log_last_ten >= 10; } print $output_file "\n----------------------Last 10 Lines from log fil +e------------------------------\n"; for (@log_last_ten){ print $output_file $_; } close $read_log_file; close $output_file;
$ perl last_ten.pl
Uncaught exception from user code: No such file or directory at last_ten.pl line 10. at last_ten.pl line 10$
This same code works if I change the line:open my $read_log_file, '<', '/home/jay/my_perl_programs/log.txt' or die $!;
To:open my $read_log_file='/home/jay/my_perl_programs/log.txt';
RegardsJay
In reply to Readbackwards usage by jayu_rao
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |