http://www.perlmonks.org?node_id=913212


in reply to AJP ping

Thanks for saving me a chunk of time. A few minor tweeks were needed for me to make it work properly, the most critical was swapping out the "||" for an actual "or", the bitwise operator didn't seem to be catching the return values properly. A bit more to add and it'll be a fully functional nagios plugin A

Replies are listed 'Best First'.
Re^2: AJP ping
by jffry (Hermit) on Nov 18, 2011 at 22:37 UTC

    Actually, || is not a bit-wise operator.

    The reason that my statements like this:

    socket $sock, PF_INET, SOCK_STREAM, $proto || die $!;

    ...aren't dying properly is because , has lower operator precedence than ||. The or operator has the lowest precedence. See the perlop docs.

    This means that statement was evaluated like this:

    socket $sock, PF_INET, SOCK_STREAM, ($proto || die $!);

    ...instead of like this:

    socket ($sock, PF_INET, SOCK_STREAM, $proto) || die $!;

    And this is now making me question the wisdom of PBP's rules of:

    Don't use unnecessary parentheses for builtins and "honorary" builtins.
    Because I was thinking that functions in the Socket module were essentially honorary builtins.