read file backwards

K

kejoseph

Hi,

I need to read a file in Perl backwards but -

I have read tips about reading the file into an array and then reading
the array in the reverse. Now, bearing in mind the fact that the log
files I will be reading will be anywhere from 10-100mb, I dont think
this is a very good idea.

I have also read about using Perl modules like FileBackwards or
File::Tie.

I do not want either of the above. I need to know whether there is a
way to read it backwards without having to use any of the above. In
other words read a file backwards using "shrink-wrapped" Perl.

Do let me know if there is any such way.

Thanks,
Kevin.
 
C

Charles DeRykus

Hi,

I need to read a file in Perl backwards but -

I have read tips about reading the file into an array and then reading
the array in the reverse. Now, bearing in mind the fact that the log
files I will be reading will be anywhere from 10-100mb, I dont think
this is a very good idea.

I have also read about using Perl modules like FileBackwards or
File::Tie.

I do not want either of the above. I need to know whether there is a
way to read it backwards without having to use any of the above. In
other words read a file backwards using "shrink-wrapped" Perl.

You could use File::ReadBackwards' strategy with seek/tell. You'll
probably learn quite a bit more than you anticipated trying to emulate
that module however :)


perldoc -f seek
perldoc -f tell
 
U

Uri Guttman

CD> You could use File::ReadBackwards' strategy with seek/tell. You'll
CD> probably learn quite a bit more than you anticipated trying to emulate
CD> that module however :)

you can write a much simpler bastard version of my module for sure. the
basics are very easy. much of my work was optimizing its speed and
handling options and such. also there were some corner cases that needed
debugging. i bet it could be done in about 20-30 lines of code if
stripped down to its basics.

i always get pissed at perl hackers who claim they can't or won't use
modules. this is almost always an easy restriction to bypass, either by
loading modules in another place, putting the modules in with their own
modules (they do code in modules? is that a restriction too?) or even
just cutting/pasting the (pure perl only) module code into their stupid
large single script. the fact that they have access to perl but not
access to modules shows massive brane damage on someone's part (their
isp, the developer, the boss, the vp of stupidity).

uri
 
X

xhoster

Hi,

I need to read a file in Perl backwards but -

I have read tips about reading the file into an array and then reading
the array in the reverse. Now, bearing in mind the fact that the log
files I will be reading will be anywhere from 10-100mb, I dont think
this is a very good idea.

I have also read about using Perl modules like FileBackwards or
File::Tie.

I do not want either of the above. I need to know whether there is a
way to read it backwards without having to use any of the above.

Then do it the way the modules you don't want to use do it. They already
exist. If it can done once, it can be done again.

Xho
 
C

Charlton Wilbur

Jim Gibson said:
I agree. It like people asking "I want to hammer a nail, but I don't
want to use a hammer." People who ask such questions should really
justify why they can't or won't use modules. Otherwise, they are just
wasting your time.

The problem is, then they start justifying why, and you find out one
of a couple things.

* They're using a cut-rate web host, only have FTP access, and want a
module that's compiled.

* They're using Perl without the support of their organization, which
means they can't officially ask for modules to be installed.

* They have the false notion that modules are slow.

Trying to convince people in any of these circumstances that they
should use modules is a futile effort; once you've recommended the use
of modules, the best you can do is move on.

Charlton
 
B

Ben Morrow

Quoth Charlton Wilbur said:
The problem is, then they start justifying why, and you find out one
of a couple things.

* They're using a cut-rate web host, only have FTP access, and want a
module that's compiled.

* They're using Perl without the support of their organization, which
means they can't officially ask for modules to be installed.

* They have the false notion that modules are slow.

Trying to convince people in any of these circumstances that they
should use modules is a futile effort; once you've recommended the use
of modules, the best you can do is move on.

Or, perhaps, point them in the direction of

pp -P -o look-ma-no-modules foo

? Requires PAR to be installed on the dev machine, but this shouldn't be
a problem. Of course, for XS modules it does something *truly* evil, and
it will make the script somewhat slower, but that's not our problem.

Ben
 
K

kejoseph

Wow, I had no idea a simple query would resuilt in such hostility !

Why do I not want to use a module ? Really simple, I then have to
install the module on all the servers. If I were doing this on my test
box it would be okay, but I plan to put this script on production
servers ; not a couple or a dozen but around 50 or more. Not just that,
since this is perceived as a system change, I need to open a change
control and obtain permission from various teams/managers !

Which I why I insisted in a "shrink wrapped" solution.

Kevin.
 
U

Uri Guttman

k> Wow, I had no idea a simple query would resuilt in such hostility !
k> Why do I not want to use a module ? Really simple, I then have to
k> install the module on all the servers. If I were doing this on my test
k> box it would be okay, but I plan to put this script on production
k> servers ; not a couple or a dozen but around 50 or more. Not just that,
k> since this is perceived as a system change, I need to open a change
k> control and obtain permission from various teams/managers !

and changing a script or putting a new one on them is easier?

k> Which I why I insisted in a "shrink wrapped" solution.

and did you read the ideas about including the module code in your
script? or figuring out a way to make installing modules easier for
yourself? and 50 servers is not that many. ask around and you will find
modules in use on much larger farms than that. so come up with some
decent excused like your dog ate your server passwords. not using
modules is stupid to an extreme and you can shoot yourself in your foot
anyway you want. hell, i wrote file::readbackwards and it is open to use
any way you want. steal the code. sell it for fun and profit. but don't
be a moron who refuses help when it is offered because of lame ass
excuses. be a professsional who tries to solve the problem in the best
way possible and not someone who caves in to every little problem thrown
their way.

uri
 
X

xhoster

Wow, I had no idea a simple query would resuilt in such hostility !

Why do I not want to use a module ? Really simple, I then have to
install the module on all the servers. If I were doing this on my test
box it would be okay, but I plan to put this script on production
servers ; not a couple or a dozen but around 50 or more.

OK. No problem. After all, you are going to put your script which uses
the module on 50 servers, why should it be a problem to put the module
it uses on 50 servers?
Not just that,
since this is perceived as a system change, I need to open a change
control and obtain permission from various teams/managers !

But you don't need obtain permission to install your own home-rolled crap
on the servers? Sorry, but if your management micromanages you to such
an extent that you can't get them to install a very popular CPAN module,
then you should be asking your management, not us, for the antidote to
their own cool-aid.

Xho
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top