X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=db-hash;fp=db-hash;h=a660cd7b4aa42b28300d57f7d0e0fdf8b75c73d7;hb=0be93ec7fea891c3fd1733198ca98ef385dc8bcc;hp=d9ad8af30d0746c9b89e9e35da16ef65ac5efcfb;hpb=ecb606acccb32483a7aad290547bc5b853094158;p=bin.git diff --git a/db-hash b/db-hash index d9ad8af..a660cd7 100755 --- a/db-hash +++ b/db-hash @@ -27,6 +27,8 @@ db-hash - create a database and query using it --dump, -D dump dbname --missing-newline, -n output a newline for unhashed keys --include-key, -k output the key as well as the value + --reverse, -r reverse (values to key) + --key-to-itself map key to itself --debug, -d debugging level (Default 0) --help, -h display this help --man, -m display manual @@ -52,6 +54,14 @@ Dump database to stdout Output the key as well as the value. (Off by default) +=item B<--reverse> + +Map values to a key + +=item B<--key-to-itself> + +Map the key to itself (On by default in reverse hashes) + =item B<--missing-newline,-n> If a key doesn't exist in the database, output a newline. (Forced on @@ -102,6 +112,7 @@ GetOptions(\%options, 'dump|D', 'include_key|include-key|k!', 'reverse|r!', + 'key_to_itself|key-to-itself|K', 'missing_newline|missing-newline|n!', 'debug|d+','help|h|?','man|m'); @@ -132,6 +143,12 @@ else { die "Unable to open $db for writing: $!"; } +if ($options{reverse}) { + if (not exists $options{key_to_itself}) { + $options{key_to_itself} = 1; + } +} + if (not defined $options{include_key}) { $options{include_key} = $options{dump} ? 0 : 1; } @@ -143,8 +160,8 @@ if ($options{update} or $options{create}) { chomp; my ($key,@val) = split /\t/; if ($options{reverse}) { - for my $val_key (@val) { - $fast_db{$val_key} = [make_list($fast_db{$val_key})//[],$key]; + for my $val_key (@val,$options{key_to_itself}?$key:()) { + $fast_db{$val_key} = [make_list($fast_db{$val_key} // []),$key]; } } else {