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:
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 |