diff options
author | Daniel Friesel <derf@derf.homelinux.org> | 2009-05-29 18:35:35 +0200 |
---|---|---|
committer | Daniel Friesel <derf@derf.homelinux.org> | 2009-05-29 18:40:58 +0200 |
commit | b22c09bbe09753e92b4515d1bae45405aef86f22 (patch) | |
tree | 757ad881cce04662881e18af26856baa8f3e4a80 /bin | |
parent | c3c4b53115fb92f5227d032fce084d4ce55006da (diff) |
envstore: Use Simplestore library
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/envstore | 24 |
1 files changed, 3 insertions, 21 deletions
diff --git a/bin/envstore b/bin/envstore index afc9f3e..adf8230 100755 --- a/bin/envstore +++ b/bin/envstore @@ -4,6 +4,7 @@ ## License: WTFPL <http://sam.zoy.org/wtfpl> use strict; use warnings; +use Simplestore; my $store_file = "/tmp/.envstore-$>"; my %store; @@ -38,32 +39,13 @@ sub check_store { } sub load_store { - my ($key, $value); return unless check_store; - open(my $handle, '<', $store_file) or die("Cannot read $store_file: $!"); - while (<$handle>) { - chomp; - /^(\S+)\s+(.*)$/ or next; - ($key, $value) = ($1, $2); - if (exists($store{$key})) { - $store{$key} .= "\n$value"; - } else { - $store{$key} = $value; - } - } - close($handle); + %store = %{load($store_file) || {}}; } sub save_store { - my $key; umask(0077); - open(my $handle, '>', $store_file) or die("Cannot open $store_file: $!"); - foreach $key (keys(%store)) { - foreach (split(/\n/, $store{$key})) { - print $handle "$key\t$_\n"; - } - } - close($handle); + save($store_file, \%store); } sub get_keyvalue { |