Easy way to reverse file read in perl?

I would like to know if there is an easy way to read a file in reverse.

In other words, read from the end of the file to the start of the file instead of start to end. I feel it would be more efficient rather than loading it into an array and then reversing it in memory, to just load it already reversed.
open(R,"$my_file");
# read file in reverse with <R>
close(R);

Open in new window

LVL 1
dr34m3rsAsked:
Who is Participating?
 
ozoConnect With a Mentor Commented:
print reverse <R>;


or
open my $rev, '<:reverse', $file;

or
0
 
ozoCommented:
or

use File::ReadBackwards ;
0
 
ozoCommented:
or  
 use Tie::File;
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

 
masheikCommented:
hi, try this code
open( FILE, "<$file_to_reverse" )
  or die( "Can't open file file_to_reverse: $!" );
 
@lines = reverse <FILE>;
 
foreach $line (@lines)
 {
  # do something with $line
 }

Open in new window

0
 
FishMongerCommented:
0
 
dr34m3rsAuthor Commented:
Thanks!
0
 
dr34m3rsAuthor Commented:
Perfect, thanks.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.