Want to understand the example line of code given by @ getlogin for getlogin
$login = getlogin || getpwuid($<) || "Kilroy";
It looks like he's trying to get the username from getlogin or getpwuid , but if either fails, use Kilroy . Maybe I'm wrong, so please correct me. Also, I used getlogin() in previous scripts - is there a difference between getlogin() and getlogin ?
What protects this code? Also, what is the purpose of $< ? I'm not quite sure what to look for, looking at what $< and what it does.
EDITfound this in the special variables section - still don't know why this is needed or what does in the example above
$<
The real uid of this process. (Mnemonic: it's you you came from if you use setuid.) You can change both the real uid and the effective uid at the same time using POSIX :: setuid (). Since changes to $ <require a system call, check $! after trying to change, detect possible errors.
EDIT x2Is this line comparable to the above example? (I am currently using to avoid any potential cron problems running the script - I have never encountered this problem, but I try to avoid any theoretical problem)
my $username = getlogin(); if(!($username)){$username = 'jsmith';}
source share