in reply to How to map a directory tree to a perl hash tree

May be it would be suitable to use tied hash (see e.g. Tie::Dir)? Do you really need to load all the directory tree into the memory before scanning?

-- brother ab
  • Comment on Re: How to map a directory tree to a perl hash tree

Replies are listed 'Best First'.
Re: Re: How to map a directory tree to a perl hash tree
by Rudif (Hermit) on Mar 12, 2001 at 02:15 UTC
    May be it would be suitable to use tied hash(see e.g. Tie::Dir)?
    Tie::Dir handles files in one directory. It should be posible to write a Tie::DirTree along similar lines.

    At times I used Tie modules (Win32::OLE, Tie::Registry), but at this stage I don't have a feel for the advantages of a Tie module relative to a plain module. I suppose a Tie module adds syntactic convenience. Can you or any other Monk elaborate on this?

    Do you really need to load all the directory tree into the memory before scanning?

    It depends on what I want to do. A simple job (e.g. count the number of .html files and compute their total size) can be done simply in the find's wanted subroutine.
    For more elaborate jobs it might be better to first extract the relevant directory and file information into a Perl structure and then work on that structure, for example:
    • generate a graphical representation of the directory tree for a browser (javascript, html, chm)
    • compare the perl/html tree with perl/lib and per/site/lib trees to find .pm and .pod files that have no corresponding .html file, and make that file
    Rudif