in reply to getlogin works on debian but not ubuntu?

perldoc -f getlogin

getlogin This implements the C library function of the same name +, which on most systems returns the current login from /etc/utm +p, if any. If null, use "getpwuid". $login = getlogin || getpwuid($<) || "Kilroy";

I'm on ubuntu, and this ...

perl -e 'print getlogin || getpwuid($<)' lanx

works for me.

Cheers Rolf

Replies are listed 'Best First'.
Re^2: getlogin works on debian but not ubuntu?
by bcrowell2 (Friar) on Jan 07, 2013 at 01:33 UTC
    Interesting. When I run your code on ubuntu, I get this:
    perl -e 'print getlogin || getpwuid($<)' bcrowellx10001000Ben Crowell,,,/home/bcrowell/bin/bash
    I guess getlogin fails, and that puts getpwuid's array output in scalar context or something? Dunno why it works differently on two versions of ubuntu.
      well getlogin worked for me, so getpwuid was never executed, just putting scalar in front seems to solve the issue for both of us (I wasn't thinking about print's list context)

      perl -e 'print scalar getpwuid($<) ' lanx

      Cheers Rolf

        Yeah, that works. I wonder if I should file a bug report on this...I'm not convinced I understand what's going on well enough to file a useful one. I assume per's getlogin() is just a wrapper for the C function, so maybe this is a bug in the C libraries in ubuntu precise?