NAME
Meta::Utils::Hash - general base utility library for many hash functions.
COPYRIGHT
Copyright (C) 2001 Mark Veltzer; All rights reserved.
LICENSE
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
DETAILS
MANIFEST: Hash.pm PROJECT: meta
SYNOPSIS
package foo;
use Meta::Utils::Hash qw();
my(%hash);
Meta::Utils::Hash::print(*FILE,\%hash);
DESCRIPTION
This is a general utility perl library for all kinds of hash routines. This mainly iterates hashes using the each builtin which is the fastest to do the job and like the list library uses refernces to avoid duplication whereever possible.
EXPORTS
size($)
empty($)
notempty($)
read($)
read_exe($)
cmp($$$$$)
print($$)
to_list($)
add_hash($$)
remove_hash($$$)
add_prefix($$)
add_suffix($$)
system($$$$)
add_key_prefix($$)
add_key_suffix($$)
filter_prefix($$$)
filter_prefix_add($$$$)
filter_multi($$$$)
filter_suffix($$$)
filter_regexp($$$)
filter_regexp_add($$$$)
filter_file_sing_regexp($$$)
filter_which($$$)
filter_exists($)
filter_notexists($)
save($$)
load($$)
FUNCTION DOCUMENTATION
- cmp($$$$$)
-
This functions compares two hashes according to keys and prints the values which exists in any of them but not in the other The return value is a boolean which is true iff the two hashes are equal. The routine also receives a boolean value telling it to be verbose or not.
- print($$)
-
This prints out the hash given to it. The first argument is a file.
- to_list($)
-
This takes a hash reference as input and produces a list which has all the keys in the hash in it. since the keys in the hash are unique the list is unique also...:)
- add_hash($$)
-
This function receives two hashes and adds the second one to the first one the fastest way possible.
- remove_hash($$$)
-
This function receives: 0. A source hash. 1. A hash to remove from the source hash. 2. A strict parameter to tell the function whether to die if an element is in the subtracted hash but not in the source one. The function changes the source hash so as not to contain any elements in the removed hash. The function doesnt return anything.
- add_prefix($$)
-
This routine adds a constant prefix to all the element in a hash. Traversal (ofcourse) is using the each operator
- add_suffix($$)
-
This routine adds a constant suffix to all the element in a hash. Traversal (ofcourse) is using the each operator
- add_key_prefix($$)
-
This routine adds a constant prefix to all the keys in a hash. Traversal (ofcourse) is using the each operator
- add_key_suffix($$)
-
This routine adds a constant suffix to all the keys in a hash. Traversal (ofcourse) is using the each operator.
- read($)
-
This reads a hash table from a file by assuming that every line is a key and giving all the keys a value of undef. That means that the key will exist but the value will be undefined.
- read_exe($)
-
This routine is the same as read except that the argument is a command line to run out of which will come the stdout file that we need to run. Why not just dump the outcome to a temp file and then read it using the previous routine ? because its stupid and uses the disk which we do not need to do... What we do is just pipe the output to a file that we open and execute the same algorithm as before. As it turns out we do call the previous routine but we change the file argument to mean "the stdout stream that comes out of the "$cmd" command"...
- filter_prefix($$$)
-
This routines receives a hash and a prefix and returns a hash with only the elements in the original hash which have such a prefix... This also receives the a third argument that instructs it to act as a negative or a positive filter.
- filter_prefix_add($$$$)
-
This routine filters according to prefix and instruction a certain hash and adds the results to a second.
- filter_multi($$$$)
-
This one is a full filter. This gets: 0. a hash. 1. whether to do filtering or not. 2. boolean indicating whether filter is negative or positive. 3. list of modules for filtering data. And does the entire filtering process in an efficient manner.
- filter_suffix($$$)
-
This routines receives a hash and a suffix and returns a hash with only the elements in the original hash which had such a suffix... This also receives the a third argument that instructs it to act as a negative or a positive filter.
- filter_regexp($$$)
-
This routine filters to the result hash all elements of the hash it gets which match a regular expression. There is also a third argument telling the filter to act as positive or negative.
- filter_regexp_add($$$$)
-
This routine adds to the received hash all the elements of the hash that match/not match (according to the posi argument) elements of the current hash.
- empty($)
-
This routine receives a hash reference. This routine returns a boolean value according to whether the hash is empty or not
- notempty($)
-
This routine receives a hash reference. This routine returns a boolean value accroding to whether the hash is not empty or not
- system($$$$)
-
This routine runs a system command for all keys of a hash. The inputs are: the hash,the system command,demo and verbose.
- size($)
-
This routine returns the number of elements in the hash (actual elements and not in the strange convention for perl where you need to do i=0;i<=num...
- filter_file_sing_regexp($$$)
-
This routine receives a hash and a regular expression and returns a hash containing only the elements in the hash which are pointers to files which contain a the regular expression. This also receives as the third variable whether to print the matched lines or not (this is passes along to Meta::Utils::File::File::check_sing_regexp).
- filter_which()
-
This needs to be written.
- filter_notexists($)
-
This does the exact opposite of the previous routine. Should we also have the same routine that actually does the manipulation on the list itself ? it would be faster...
- save($$)
-
This routine saves the entire hash to a disk file.
- load($$)
-
This routine loads the entire hash from a disk file.
BUGS
None.
AUTHOR
Mark Veltzer <mark2776@yahoo.com>
HISTORY
start of revision info 1 Mon Jan 1 16:38:12 2001 MV initial code brought in 2 Thu Jan 4 06:30:32 2001 MV this time really make the databases work 3 Sat Jan 6 11:39:39 2001 MV make quality checks on perl code 4 Sat Jan 6 17:14:09 2001 MV more perl checks 5 Sun Jan 7 18:17:29 2001 MV make Meta::Utils::Opts object oriented 6 Tue Jan 9 17:00:22 2001 MV fix up perl checks 7 Tue Jan 9 19:29:31 2001 MV fix todo items look in pod documentation 8 Wed Jan 10 12:05:55 2001 MV more on tests/more checks to perl 9 Thu Jan 11 09:43:58 2001 MV fix all tests change 10 Fri Jan 12 09:25:33 2001 MV more perl quality 11 Thu Jan 18 15:59:13 2001 MV correct die usage 12 Sun Jan 28 02:34:56 2001 MV perl code quality 13 Sun Jan 28 13:51:26 2001 MV more perl quality 14 Tue Jan 30 03:03:17 2001 MV more perl quality 15 Sat Feb 3 23:41:08 2001 MV perl documentation 16 Mon Feb 5 03:21:02 2001 MV more perl quality 17 Tue Feb 6 01:04:52 2001 MV perl qulity code 18 Tue Feb 6 07:02:13 2001 MV more perl code quality 19 Tue Feb 6 08:47:46 2001 MV more perl quality 20 Tue Feb 6 22:19:51 2001 MV revision change end of revision info
SEE ALSO
Nothing.
TODO
-improve the print routine by adding modifiers to the output.
-cant we do the size more efficiently ?
-do the sub filter_file_mult_regexp($$) routine
-the read_exe routine gets a shell command line and sometimes you dont want that overhead. make a routine that does the same and doesnt pass through the shell and check where the current routine is used and replace where ever possible.