in reply to Tie::RefHash

I assume you're talking about the semi-sparce info at perlman:Tie::RefHash. However, this will point you toward some more info such as perltie.
Commonly installed yes since it comes in the distributions since 5.004 IIRC.

Replies are listed 'Best First'.
Re: Re: Tie::RefHash
by malaga (Pilgrim) on Jan 30, 2001 at 04:16 UTC
    thanks i'll take a look. i didn't find it in the @INC list on verio, and usually they have the common ones.
Re: Re: Tie::RefHash
by malaga (Pilgrim) on Jan 30, 2001 at 04:32 UTC
    Looked at that information and still not clear. Would the Tie.pm help me at all in this situation: i have 6 tab delimited text files, all with a common field (column). i need to pull information from each, based on that one field. should i open each one, pull the appropriate row into an array, etc, or would the Tie.pm do anything to automate this in any way? or is it's intended use totally unrelated to what i'm doing?

      I think that you'd be better off using something like DBD::CSV or Text::CSV.

      tie is intended to be used to tie a Perl variable (scalar, array, or hash) with a subroutine so that, to the user, it seems that they're using a regular Perl variable but every time they access that variable they are, in reality, invoking a subroutine call that handles the data in a form that is maybe totally different from normal Perl variables.

      The reason that tie might be used with database modules is that it provides a simple, intuitive interface to the data. For example, the user can get a scalar variable tied to a DB field that, every time they read the value of that variable, the DB module looks up the field data for the next record in the DB. Or they could receive a tied hash that looks up field values by name instead of the user having to remember what order the fields are in and without the DB having to read an entire record into memory at once.

      So, while you could build a tied variable interface to the files, you'll still have to build the routines to read that data in from the files. And for that, you'd probably want to go with one of the two CSV modules I mentioned above or, perhaps, one of the DBI modules...

      Forgive me if I've rambled a bit and am not making any sense. It happens some times!  =) Let me know if that helps (or doesn't)!

      bbfu

        i looked up both of those modules, but the server i'm working on doesn't have them, and it's next to impossible to get anything added, so it's a moot point. but the Text::CSV looked like it might have helped. thanks!

      I don't think tying is going to help you the way you hope it will.

      You're still going to have to write the methods or subs that open the text files and search through and aggregate your data (which is what you were trying to avoid.) All tying does is give you a nice, clean, familiar interface to use (although nothing you can't do outside of tying.) In other words, if you tie a hash, you'd be able to access your data like

      tie %hash, 'MyHashClass', @files; my @data = $hash{$key}; # convienent!

      but somewhere in the background you'll still need something like

      package MyHashClass; use strict; use Carp; use Tie::Hash; @MyHashClass::ISA = qw/ Tie::StdHash /; sub FETCH { my ($self, $key) = @_; my @ret = (); foreach my $filename ( @files ) { open( F, $filename ) or croak "$!"; while( <F> ) { if ( matches ) { push @ret, $_; } } close F; } return @ret; } 1;

      Hmm. Actually this is horribly inefficient and you wouldn't want to do it this way. You'd probably open all of the files when the hash is tied or something.

      But I think I'm getting off track. I guess my point is that tying isn't going to save you any work.

      If you have a lot of data or you're going to have to search through it very often, it's worth combining and/or sorting your files (or converting to a database like Berkeley DB (DB_File)) so you can search them more efficiently. Otherwise doing what you say (open each one, pull the appropriate row, etc.) will work.

        yeah, i wish i had db available on the server, but i don't. thanks for your help. i won't pursue the Tie pm thanks.