Your skill will accomplish what the force of many cannot |
|
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
I'd put the records in an array of hashes ($data) then have a hash of hashes of arrays ($index) that returns record numbers (nah, make that references to the record hashes). Then let the user select which field(s) they want the index computed for. Then the user could do things like: for example:
The main reason I thought of this is because I thought your routine would be nice to use even when the first field isn't an ID number that is unique. And, yes, I'd make the interface OO so you could have a method for setting the delimiter and for adding things to the index after the fact. Then if you have multiple files that use the same delimiter and ID fields, you could reuse the configuration of one for loading another via my $other= $one->new("other.txt");. Then have the object also be a reference to a tied hash where $obj->{}->[$N] gets a ref to record number $N and $obj->{keyFieldName}{fieldValue}[$I] gets a ref to the $I'th record having a matching key value. Also, each record should keep its record number in the field named "".
Making it OO is pretty easy and once you do that, adding all of the features I mentioned is pretty easy and can be done incrementally. Making an object that is also a tied reference to a hash is confusing at first, so let me know if you'd like help there. This probably sounds like a lot of work but I don't think that it would be. :) In reply to Re: Another flatfile thingy
by tye
|
|