http://qs321.pair.com?node_id=710028


in reply to Glib based forking server with root messaging

What is your reasoning for the numeric operators in the conditionals instead of string operators (like "ge")? How are you avoiding "Argument isn't numeric in numeric" warnings? Or are you avoiding them?
$condition >= 'hup' or $condition >= 'err'
HTH,
Charles

Replies are listed 'Best First'.
Re^2: Glib based forking server with root messaging
by zentara (Archbishop) on Sep 09, 2008 at 11:27 UTC
    It's some Glib overloading. From muppet's explanation on the Perl/Gtk2 maillist:
    > On 25/02/07, muppet <scott@asofyet.org> wrote: >> Well, TIMTOWDI, of course. :-) But, yes, the ">=" operator, which +is >> overloaded for Glib::Flags bitsets to mean the same as "&", which i +s >> "are all of the flags listed on the right hand side set in the left >> hand side?" is how i would write it. > > I can see that &, >= and * should be the same for this example. > >> The Glib::Flags operators are explained in the "This Is Now That" >> section of the Glib manpage. > > But in the manpage, it implies (to me at least) that there is a > difference between &, >= and *. Is there difference? For a boolean test, no. & and >= are implemented differently, but * and & are the same. The names (and operators) are derived from set theory, but you can also use any knowledge of binary logic operations + from C. (Warning: potentially redundant but intended-to-be complete information follows.) Glib.pm contains this: package Glib::Flags; use overload 'bool' => \&bool, '+' => \&union, '|' => \&union, '-' => \&sub, '>=' => \&ge, '==' => \&eq, 'eq' => \&eq, # eq for is_deeply in Test::More '*' => \&intersect, '&' => \&intersect, '/' => \&xor, '^' => \&xor, '@{}' => \&as_arrayref, '""' => sub { "[ @{$_[0]} ]" }, fallback => 1; Those subs are implemented essentially like this: bool := NOT NOT a if any of the bits in a are set, the expression evaluates to TR +UE union := a OR b the result contains all of the bits set in a and b that is, the result is the union of the two sets. the | mnemonic is for the C (and Perl) bitwise OR operator. the + mnemonic is for union of two sets -- you're adding them together. sub := a AND NOT b the result contains all the bits set in a minus the bits that were also on in b. this is subtracting the set of b from the set of a. the - mnemonic is awesome, because "a & ~b" is bizarre looking. ge := (a AND b) IS b the result is TRUE if the bits in b are on in a. other bits may be on in a, but they are ignored (by the AND). hence, this is true if the set of a is greater than or equal to the set of b. eq := a IS b the result is TRUE iff the same set of bits are on in both. intersect := a AND b the result contains all of the bits that are on in both a and b +. that is, it returns the intersection of sets a and b. the & mnemonic is the C (and Perl) bitwise AND operator. the * mnemonic is for the intersection of two sets. xor := a XOR b the result contains all of the bits that are on in either or both a and b. the bits that are on in both are not included; this is the exclusive or of the two sets. the ^ mnemonic is for the C (and Perl) bitwise XOR operator. All that said, i think the only ones i have ever used are the >= and bool operators.

    I'm not really a human, but I play one on earth Remember How Lucky You Are