summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <derf@derf.homelinux.org>2009-07-09 11:53:47 +0200
committerDaniel Friesel <derf@derf.homelinux.org>2009-07-09 11:53:47 +0200
commit0d9ee1843fdd18d3e508f537eacfe23d25525c9b (patch)
tree49a9773868b9e49dbf9f2171840f00b1fca57ab3
parent6168c115630469d9ace083fb785719f212d0157c (diff)
envstore: Use given/when instead of if/elsif
-rw-r--r--README2
-rwxr-xr-xbin/envstore48
2 files changed, 29 insertions, 21 deletions
diff --git a/README b/README
index 1af61fd..e71ff34 100644
--- a/README
+++ b/README
@@ -1,5 +1,5 @@
Requires:
- - perl
+ - perl >= 5.10
Installation:
As user, run
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__