I am trying to add a long DNA sequence into my database. Reading some other threads here, it was suggested to use CRC32 as a way to implement a unique constraint on fields where the length of the string is too long for unique key.
I am trying to check if a DNA sequence already exists in my database by converting it with
String::CRC32 into CRC32 hash. However, I can't seem to use pack or unpack to properly store the data type for comparison to my database.
my $crc32=crc32("$sequence"); #check crc32 of sequence
my $th=$dbh->prepare(qq(SELECT COUNT(1) FROM Sequence WHERE Seq_Checks
+um=$crc32)); #check if it already exists
$th->execute();
my $test=$th->fetch()->[0];
print "$test\n"; #output if it exists
This gives me a segmentation fault
this is mySQL 5.7 and perl 5.22.1
UPDATE: Good lord. After reading a lot about the CRC32 function in SQL. I learned that it spits out a 32bit unsigned integer which is basically 0-4million something. So this whole time I assumed it was giving me binary so I was storing it binary. I switched it to unsigned int size 10 and that is the exact size of 32bit. So I don't have to mess with binary values.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.