use File::ReadBackwards ;
# Object interface
$bw = File::ReadBackwards->new( '$file' ) or
die "can't read '$file' $!" ;
This won't have the desired effect because you have enclosed the variable holding the file name inside single quotes and so it won't interpolate. Just lose the quotes entirely - they are serving no purpose here. eg:
#!/usr/bin/env perl
use strict;
use warnings;
use utf8;
use File::ReadBackwards;
my $file = 'weblog.log';
my $bw = File::ReadBackwards->new ($file)
or die "can't read '$file' $!";
while (defined (my $log_line = $bw->readline)) {
print $log_line;
}
$ cat weblog.log
first line
second line
line the third
$ ./rb.pl
line the third
second line
first line
$
The script you have shown us looks to have been written a very long time ago. There are many ways in which it would be different if written today but here are two fairly simple but effective tips:
- Use strict and warnings as I have done in the example above. These will save you time and again.
- Replace all those repetitive if ($hour eq "18") ... blocks with a loop or some broader logic. When there is an obvious pattern like that there is no need to go repeating yourself over and over. Better yet, use one of the many good time-handling modules so you don't have to bother with any of that low-level stuff in the first place.
Good luck!
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.