read file backwards

Discussion in 'Perl Misc' started by kejoseph@hotmail.com, Aug 23, 2006.

  1. Guest

    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.
    , Aug 23, 2006
    #1
    1. Advertising

  2. wrote:
    > 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


    --
    Charles DeRykus
    Charles DeRykus, Aug 23, 2006
    #2
    1. Advertising

  3. Uri Guttman Guest

    >>>>> "CD" == Charles DeRykus <> writes:

    CD> wrote:
    >> 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.
    >>


    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

    --
    Uri Guttman ------ -------- http://www.stemsystems.com
    --Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
    Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
    Uri Guttman, Aug 23, 2006
    #3
  4. Guest

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

    --
    -------------------- http://NewsReader.Com/ --------------------
    Usenet Newsgroup Service $9.95/Month 30GB
    , Aug 23, 2006
    #4
  5. Jim Gibson <> writes:

    > 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
    Charlton Wilbur, Aug 24, 2006
    #5
  6. Ben Morrow Guest

    Quoth Charlton Wilbur <>:
    > Jim Gibson <> writes:
    >
    > > 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.


    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

    --
    We do not stop playing because we grow old;
    we grow old because we stop playing.
    Ben Morrow, Aug 24, 2006
    #6
  7. Guest

    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.
    , Aug 27, 2006
    #7
  8. Uri Guttman Guest

    >>>>> "k" == kejoseph <> writes:

    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

    --
    Uri Guttman ------ -------- http://www.stemsystems.com
    --Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
    Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
    Uri Guttman, Aug 27, 2006
    #8
  9. <> wrote:

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



    You must be a slow learner then, since this isn't the first
    time you've brought out hostility here.

    Message-ID: <>


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
    Tad McClellan, Aug 27, 2006
    #9
  10. Guest

    wrote:

    > 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

    --
    -------------------- http://NewsReader.Com/ --------------------
    Usenet Newsgroup Service $9.95/Month 30GB
    , Aug 28, 2006
    #10
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. SK
    Replies:
    15
    Views:
    790
    Karl Heinz Buchegger
    Jun 17, 2004
  2. Matt DeFoor

    reading file backwards and parsing

    Matt DeFoor, Apr 12, 2004, in forum: C Programming
    Replies:
    11
    Views:
    4,040
    Barry Schwarz
    Apr 14, 2004
  3. Jay
    Replies:
    7
    Views:
    10,867
    Paul Rubin
    Oct 1, 2004
  4. Shahid Juma

    Reading File in Backwards

    Shahid Juma, Dec 23, 2004, in forum: ASP General
    Replies:
    5
    Views:
    154
    Dave Anderson
    Dec 23, 2004
  5. Alex Dowad
    Replies:
    4
    Views:
    267
    Michel Demazure
    May 1, 2010
Loading...

Share This Page