jayu_rao has asked for the wisdom of the Perl Monks concerning the following question:
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: ReadBackwards usage
by Athanasius (Archbishop) on Mar 16, 2015 at 06:18 UTC | |
by jayu_rao (Sexton) on Mar 16, 2015 at 07:17 UTC | |
by Athanasius (Archbishop) on Mar 16, 2015 at 07:48 UTC | |
|
Re: Readbackwards usage
by NetWallah (Canon) on Mar 16, 2015 at 06:03 UTC | |
|
Re: Readbackwards usage
by Marshall (Canon) on Mar 16, 2015 at 12:02 UTC |