in reply to Re: checking mySQL database for unique CRC32 as proxy for long string
in thread checking mySQL database for unique CRC32 as proxy for long string
#!\C:\Strawberry\perl\bin\perl use strict; use warnings; use DBI; use DBD::mysql; use String::CRC32; #DATA SOURCE NAME my $dsn = "dbi:mysql:database=$database;host=$host;port=$port"; #PERL DBI CONNECT my $dbh=DBI->connect($dsn,$user,$pw, { PrintError => 0, RaiseError => 1, AutoCommit => 1, }) or die $DBI::errstr; #Read input file to load into DB open(INFILE, "<$ARGV[0]") or die "cannot open file:$!\n"; <INFILE>; #skip header for(<INFILE>){ #split line my @line=split("\t", $_); #check correct number of columns if (scalar(@line)>=11) { #parse columns my $chr=$line[0]; my $pos=$line[1]; my $sequence=$line[2]; #insert sequence my $crc32=crc32("$sequence"); #check crc32 of sequence print unpack($crc32)."\n"; my $th=$dbh->prepare(qq(SELECT COUNT(1) FROM Sequence WHERE Se +q_Checksum=$crc32)); $th->execute(); my $test=$th->fetch()->[0]; print "$test\n"; #if ($th->fetch()->[0]) { # print "Sequence already in database!\n"; #} #else { # print "New sequence detected, inserting into database wit +h unique checksum.\n"; # $dbh->do("INSERT INTO Sequence(Sequence) VALUES($sequence +)"); # $dbh->do("INSERT INTO Sequence(Seq_Checksum) VALUES($crc3 +2)"); # #} # } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: checking mySQL database for unique CRC32 as proxy for long string
by diyaz (Beadle) on Jan 22, 2016 at 23:57 UTC |