getpwuid.
$login = getlogin || getpwuid($<) || "Kilroy";
Do not consider getlogin for authentication: it is not as secure as getpwuid.
getlogin