diff options
author | John <john@ankarstrom.se> | 2019-06-01 14:19:52 +0200 |
---|---|---|
committer | John <john@ankarstrom.se> | 2019-06-01 14:19:52 +0200 |
commit | 351153eae7a319a25ef1365279257f7019b733cf (patch) | |
tree | 9df8ae26639867eb5bf78cf2b7dbc446abd92ac5 | |
parent | 4c6017f37208f61e236d13a589e452c65e36bc13 (diff) | |
download | dwim-351153eae7a319a25ef1365279257f7019b733cf.tar.gz |
env subroutine: simpler default assignment
-rwxr-xr-x | dwim.pl | 19 |
1 files changed, 11 insertions, 8 deletions
@@ -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}; +} |