aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn <john@ankarstrom.se>2019-06-01 14:19:52 +0200
committerJohn <john@ankarstrom.se>2019-06-01 14:19:52 +0200
commit351153eae7a319a25ef1365279257f7019b733cf (patch)
tree9df8ae26639867eb5bf78cf2b7dbc446abd92ac5
parent4c6017f37208f61e236d13a589e452c65e36bc13 (diff)
downloaddwim-351153eae7a319a25ef1365279257f7019b733cf.tar.gz
env subroutine: simpler default assignment
-rwxr-xr-xdwim.pl19
1 files changed, 11 insertions, 8 deletions
diff --git a/dwim.pl b/dwim.pl
index 462fdbb..6d2c445 100755
--- a/dwim.pl
+++ b/dwim.pl
@@ -12,14 +12,10 @@ my $p;
$p = $ARGV[0] if defined $ARGV[0];
$p = `xsel -o` if not defined $ARGV[0];
-our $OPENER = $ENV{OPENER};
-our $EDITOR = $ENV{EDITOR};
-our $MAILER = $ENV{MAILER};
-our $MAILROOT = $ENV{MAILROOT};
-$OPENER = "u" if not defined $OPENER;
-$EDITOR = "vi" if not defined $EDITOR;
-$MAILER = "mutt" if not defined $MAILER;
-$MAILROOT = "/home/john/mail/" if not defined $MAILROOT;
+my $OPENER = env (OPENER => "u");
+my $EDITOR = env (EDITOR => "vi");
+my $MAILER = env (MAILER => "mutt");
+my $MAILROOT = env (MAILROOT => "/home/john/mail/");
for ($p) {
# web address
@@ -66,3 +62,10 @@ sub path {
die "couldn't retrieve directory\n" if ! -d $t and ! -d ($t = dirname $t);
return "$t/$f";
}
+
+sub env {
+ my %h = @_;
+ my $k = (keys %h)[0];
+ return $ENV{$k} if defined ${ENV}{$k};
+ return $h{$k};
+}