One thing you will need to be aware of when dealing with MySQL SET types is that unless you are using a perl that is built for either a 64-bit platform, or has been built to enable 64-bit ints, if you attempt to manipulate them using the math operators, you are likely to come unstuck, as they will probably be converted to doubles and they only support 53-bits of precision.

If your on a 32-bit platform you should treat them as 8 byte strings (carefully avoiding allowing them to get treated as unicode!), and only use vec to access the bits. The downside of that is that depending upon your platform vec may index the bits in a different order to the way they are described by the MySQL docs. That's most likely to be the case if (for example), the MySQL server was running on a Solaris box and your program on Intel; or vice versa; or many other combinations.

The only sure way to know will be to experiment with setting a few bits, insert them into your DB and then query the DB via it's own client to see which interpretation it puts upon the bits you set.

The alternative would be to use pack & unpack with either 'b64' or 'B64' as appropriate to expand the bits into an array. If your program needs to run cross platform, you could do something like:

use Config; my $setTemplate; if( $Config{ byteorder } eq '1234' ) { $setTemplate = 'B64'; } elsif( $Config{ byteorder } eq '3412' ) { $setTemplate = 'b64'; } else { die "What kind of cpu are you using for dogs sake:)!"; } ...

Note: The above is untested and I probably have guessed wrong about which template goes with which ordering!


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

In reply to Re: Flipping bits and using flags by BrowserUk
in thread Flipping bits and using flags by BMaximus

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.