diff options
author | Daniel Friesel <derf@derf.homelinux.org> | 2009-07-09 11:53:47 +0200 |
---|---|---|
committer | Daniel Friesel <derf@derf.homelinux.org> | 2009-07-09 11:53:47 +0200 |
commit | 0d9ee1843fdd18d3e508f537eacfe23d25525c9b (patch) | |
tree | 49a9773868b9e49dbf9f2171840f00b1fca57ab3 /bin | |
parent | 6168c115630469d9ace083fb785719f212d0157c (diff) |
envstore: Use given/when instead of if/elsif
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/envstore | 48 |
1 files changed, 28 insertions, 20 deletions
diff --git a/bin/envstore b/bin/envstore index b9d6d66..cc5ad96 100755 --- a/bin/envstore +++ b/bin/envstore @@ -4,6 +4,7 @@ ## License: WTFPL <http://sam.zoy.org/wtfpl> use strict; use warnings; +use 5.010; use Pod::Usage; use Storable 'nstore', 'retrieve'; @@ -67,28 +68,35 @@ sub get_keyvalue { usage unless defined($action); load_store; -if ($action eq 'save') { - usage unless defined($arg); - ($key, $value) = get_keyvalue($arg, $arg2); - $store{$key} = $value; - save_store; -} elsif ($action eq 'eval') { - while (($key, $value) = each(%store)) { - $value =~ s/'/'"'"'/g; - print "export $key='$value'\n"; +given ($action) { + when ('save') { + usage unless defined($arg); + ($key, $value) = get_keyvalue($arg, $arg2); + $store{$key} = $value; + save_store; } -} elsif ($action eq 'show' or $action eq 'list') { - while (($key, $value) = each(%store)) { - printf("%-15s = %s\n", $key, $value); + when ('eval') { + while (($key, $value) = each(%store)) { + $value =~ s/'/'"'"'/g; + print "export $key='$value'\n"; + } + } + when (['show', 'list']) { + while (($key, $value) = each(%store)) { + printf("%-15s = %s\n", $key, $value); + } + } + when ('rm') { + usage unless defined($arg); + delete($store{$arg}); + save_store; + } + when ('clear') { + unlink($store_file); + } + default { + usage; } -} elsif ($action eq 'rm') { - usage unless defined($arg); - delete($store{$arg}); - save_store; -} elsif ($action eq 'clear') { - unlink($store_file); -} else { - usage; } __END__ |