Skip to content

Commit

Permalink
whoami: factor conditional
Browse files Browse the repository at this point in the history
* Make code even simpler by splitting USER and USERNAME checks into their own subsequent closures
* Tested this by commenting the other subs and running 'perl env -i USERNAME=bob perl whoami'
  • Loading branch information
mknos authored Jun 12, 2024
1 parent f645ad5 commit 64cd678
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion bin/whoami
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ my @coderefs = (
sub { getpwuid($>) },
sub { require Win32; Win32::LoginName() },
sub { getlogin },
sub { defined $ENV{USER} ? $ENV{USER} : $ENV{USERNAME} },
sub { $ENV{'USER'} },
sub { $ENV{'USERNAME'} },
);

foreach my $coderef ( @coderefs ) {
Expand Down

0 comments on commit 64cd678

Please sign in to comment.