in reply to Need help using File::ReadBackwards

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:

  1. Use strict and warnings as I have done in the example above. These will save you time and again.
  2. 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!


🦛

Replies are listed 'Best First'.
Re^2: Need help using File::ReadBackwards
by nixnut (Novice) on Oct 15, 2024 at 03:31 UTC
    thank you, i will try to implement what you have provided, much appreciated