M
mud_saisem
Hi there,
Could anybody tell me if there is a fast and efficient way to scan/
print a large files (1Gb+) backwards ?
I am not sure that the reverse function is the best way of doing it,
particularly for really large files.
I was thinking of maybe finding the file size in bytes and then
running through a for loop in a descending order printing the file
position with seek, but as you all properly know, that will not work
very well.
i would really like to be able to do this with out using any modules.
Any ideas ?
eg:
#!/usr/bin/perl
$filesize = -s $ARGV[0];
open(FILE, "$ARGV[0]") or die "$!\n";
for ($filesize = -s $ARGV[0]; $filesize >= 0; $filesize--)
{
seek(FILE,$filesize,0);
$line = <FILE>;
print $line;
}
close (FILE);
But my output is as follows
../file_byte_size.pl /tmp/test.txt
..
s.
ds.
rds.
ards.
wards.
kwards.
ckwards.
ackwards.
backwards.
e
le
ile
file
file
e file
he file
the file
the file
t the file
nt the file
int the file
rint the file
print the file
print the file
n print the file
an print the file
can print the file
can print the file
I can print the file
f
if
if
e if
ee if
see if
see if
o see if
to see if
to see if
e to see if
le to see if
ile to see if
file to see if
t
st
est
test
test
a test
a test
s a test
is a test
is a test
s is a test
is is a test
his is a test
This is a test
Could anybody tell me if there is a fast and efficient way to scan/
print a large files (1Gb+) backwards ?
I am not sure that the reverse function is the best way of doing it,
particularly for really large files.
I was thinking of maybe finding the file size in bytes and then
running through a for loop in a descending order printing the file
position with seek, but as you all properly know, that will not work
very well.
i would really like to be able to do this with out using any modules.
Any ideas ?
eg:
#!/usr/bin/perl
$filesize = -s $ARGV[0];
open(FILE, "$ARGV[0]") or die "$!\n";
for ($filesize = -s $ARGV[0]; $filesize >= 0; $filesize--)
{
seek(FILE,$filesize,0);
$line = <FILE>;
print $line;
}
close (FILE);
But my output is as follows
../file_byte_size.pl /tmp/test.txt
..
s.
ds.
rds.
ards.
wards.
kwards.
ckwards.
ackwards.
backwards.
e
le
ile
file
file
e file
he file
the file
the file
t the file
nt the file
int the file
rint the file
print the file
print the file
n print the file
an print the file
can print the file
can print the file
I can print the file
f
if
if
e if
ee if
see if
see if
o see if
to see if
to see if
e to see if
le to see if
ile to see if
file to see if
t
st
est
test
test
a test
a test
s a test
is a test
is a test
s is a test
is is a test
his is a test
This is a test