in reply to Re^2: Does $> have a little extra magic?
in thread Does $> have a little extra magic?

You have to admit - that's kinda ugly ;-)

# Try Windows first. my $root = eval { require Win32; Win32::IsAdminUser(); }; # If that didn't work, try Unix. $root = $> == 0 if $@;
Also has the advantage of avoiding eval STR. String evals are nasty and to be avoided where possible.

Replies are listed 'Best First'.
Re^4: Does $> have a little extra magic? ($@)
by tye (Sage) on Mar 21, 2006 at 20:06 UTC

    Using $@ to decide whether eval failed is error prone, in my experience. Instead I end my 'eval' expression with "; 1" and check whether eval returns a true value or not:

    my $root= eval { require Win32; 1 } ? Win32::IsAdminUser() : $> == 0;

    - tye