in reply to Re: Style Comments
in thread Style Comments

I once got first and last bits form a file by reading it into a string, grabbing the first bit, reversing the string, grabbing the first bit again (which was the reveresed last bit) then reversing what I grabbed back to normal :-)

I notice you use Tie::File and Im sure I read in the pod that Tie was redundant and DBI should be used.

Tie::File looked like so much fun but I was reluctant to try it so now I just read my file into @lines - which I guess has the drawback of taking up more memory space.

My reluctance is becuase the scripts I write may end up on any version of perl on any server so I dont like relying on specific modules being installed.

Is Tie::File in common use then in the general perl community?

___ /\__\ "What is the world coming to?" \/__/ www.wolispace.com

Replies are listed 'Best First'.
Re: Re: Re: Style Comments
by blokhead (Monsignor) on Sep 05, 2003 at 00:13 UTC
    I notice you use Tie::File and Im sure I read in the pod that Tie was redundant and DBI should be used.
    I don't see that anywhere in its pod, but Tie::File and DBI do completely different things. Use Tie::File when you need to access a file (any type of text file) through an array interface. Use DBI when you want to access a datasource (could be a file, or a RDBMS) through statements in a data-querying language. I don't believe either one could make the other redundant.

    Tie::File is included in the core Perl distribution since version 5.8.0, which is a pretty good indication of the robustness of its code. Apart from that, it's a pure Perl module, so you can just put the .pm file in the same directory as your script and it will work fine.

    blokhead

      Now this is good news!

      Thanks for that.. I'm off to start playing with my new toy :-)

      ___ /\__\ "what is the world coming to?" \/__/ www.wolispace.com
Re: Re: Re: Style Comments
by BrowserUk (Patriarch) on Sep 05, 2003 at 09:51 UTC

    I'm not certain, but maybe the bit of the pod you remember reading is this bit

    dbmopen HASH,DBNAME,MASK [This function has been largely superseded by the tie function.]

    Perhaps that is the source of your confusion?

    I think blokhead answered most of your concerns. All I would add is that (IMO) tie is Perls secret weapon.

    Despite some concerns about the runtime overhead (which is no worse (I think) than calling OO-methods?), it provides a really easy-to-use mechanism with a simple, consistant interface for encapsulation of almost anything behind perls built-in data structures. This gives many of the benefits that OO-ists hold so dear without requiring each new module to invent and document a completely new interface--the bit that even experienced OO-ists get wrong so often. My only wish is that self-typing and nested-ties worked more intuatively.

    I do hope that this simple and infinitely flexible mechanism for abstraction makes it into P6. Hopefully, the parrot engine will make reduce the runtime impact of magic.


    Examine what is said, not who speaks.
    "Efficiency is intelligent laziness." -David Dunham
    "When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller
    If I understand your problem, I can solve it! Of course, the same can be said for you.