How do I get the current user in Perl in a portable way?

前端 未结 2 1101
故里飘歌
故里飘歌 2021-01-04 02:21

How does one get the current user in a portable way?

This seems like an FAQ but perlport doesn\'t speak about it, maybe because some odd systems don\'t have the conc

2条回答
  •  执念已碎
    2021-01-04 03:02

    Win32::LoginName() can be used on Windows to retrieve the user name (without the domain name, so it may be ambiguous):

    use Win32;
    my $username = Win32::LoginName;
    

    Win32::pwent implements getpwuid() and other features to query the user database. Unfortunately, it failed to install on my StrawberryPerl 5.12.

提交回复
热议问题