sanjid has asked for the wisdom of the Perl Monks concerning the following question:
my script goes like this
use DBI; print "Enter your file name\n"; chomp($filename=<>); #open (OUT,">>$filename.csv") || die print "Noooooooooooooo"; #print OUT "count,date,Sample_Type,Patient_ID,Sample_Id,Doctor_Id +,Location,Rotor,Serial,QC,HEM,LIP,ICT,para\n"; #close OUT; open (IN,"$filename.txt") || die print "Noo Input"; my @file=<IN>; my $string = join('#', @file); # print "$string"; $string =~ s/\n//g; $string =~ s/\t//g; while($string=~/Equine Profile Plus\s*#(.*?) .*?(Sample. +*?)##/igs){ my($date,$line,$Sample_Type,$Patient_ID,$Sample_Id,$Doctor_Id,$Loc +ation,$Rotor,$Serial,$para,$QC,$HEM,$LIP,$ICT); $count++; $date=$1; $line=$2; #print "$line\n"; if ($line=~/Sample Type:(.*?)#/gis){ $Sample_Type=clean($1); }if ($line=~/Patient ID:(.*?)#/gis){ $Patient_ID=clean($1); }if ($line=~/Sample ID:(.*?)#/gis){ $Sample_Id=clean($1); }if ($line=~/Doctor ID:(.*?)#/gis){ $Doctor_Id=clean($1); }if ($line=~/Location:(.*?)#/gis){ $Location=clean($1); }if ($line=~/Rotor Lot Number:(.*?)#/gis){ $Rotor=clean($1); }if ($line=~/Serial Number:(.*?)#/gis){ $Serial=clean($1); }if ($line=~/#(NA+.*?GLOB.*?)#/gis){ $para=$1; $para =~ s/#/;/g; $para =~ s/\s\s/ /g; $para =~ s/\s\s/ /g; $para =~ s/\s\s/ /g; $para =~ s/\s\s/ /g; $para =~ s/\s\s/ /g; $para =~ s/\s\s/ /g; $para =~ s/ /:/g; $para =~ s/mmol\/L//g; $para =~ s/U\/L/ /g; $para =~ s/mg\/dL/ /g; $para =~ s/g\/dL/ /g; $para=clean($para); }if ($line=~/#QC(.*?) #HEM(.*?) LIP(.*?) ICT(.*?) /gis){ $QC=clean($1); $HEM=clean($2); $LIP=clean($3); $ICT=clean($4); } open (OUT,">>$filename.csv") || die print "Noooooooooooooo"; print OUT "\"$count\",\"$date\",\"$Sample_Type\",\"$Patient_ID\", +\"$Sample_Id\",\"$Doctor_Id\",\"$Location\",\"$Rotor\",\"$Serial\",\" +$QC\",\"$HEM\",\"$LIP\",\"$ICT\",\"$para\"\n"; } close OUT; #Load csv into mysql &loaddata('$filename.csv'); sub clean { my ($line) = shift (@_); $line =~ s/\n//g; $line =~ s/\r//g; $line =~ s/^\s+//g; $line =~ s/\s\s//g; $line =~ s/\s+$//g; $line =~ s/#//g; return ($line); } #init the mysql DB sub init_dbh{ my $dbh = DBI->connect ('DBI:mysql:pfam','username','password') or di +e "Can't connect to database: $DBI::errstr\n"; return $dbh; } #Load data to mysql table sub loaddata{ my ($name) = @_; my $DBH = init_dbh( ); $STH_GO = $DBH->prepare(q{ LOAD DATA LOCAL INFILE '?' INTO TABLE authors FI +ELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\r\n'; }) +or die "ERROR: ".$DBI::errstr; $STH_GO->execute($name); }
the data used is a text file ie
now my problem is i have inserted the whole data except the numeric values into the script. i have to designate the numeric values as reported value and reference range so how should i insert that into a database. please help me with the script. and is the whole script correct Thanks.VetScan VS2 Equine Profile Plus 13 Oct 2010 09:19 Sample Type: Horse Patient ID: 019-8592 Sample ID: 019-8592 Doctor ID: 1 Location: 1 Rotor Lot Number: 0052AA8 Serial Number: 0000V01219 .............................. NA+ 136 126-146 mmol/L K+ 3.0 2.5-5.2 mmol/L tCO2 28 20-33 mmol/L CK 216 120-470 U/L GLU 109 65-110 mg/dL CA 12.2 11.5-14.2 mg/dL BUN 13 7-25 mg/dL CRE 1.5 0.6-2.2 mg/dL AST 326 175-340 U/L TBIL 1.7 0.5-2.3 mg/dL GGT 5 5-24 U/L ALB 3.3 2.2-3.7 g/dL TP 7.3 5.7-8.0 g/dL GLOB 4.0 2.7-5.0 g/dL QC OK HEM 0 LIP 0 ICT 0
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: have written a script for inserting data into database but stil face probs...plz help
by kcott (Archbishop) on Oct 22, 2010 at 18:59 UTC | |
|
Re: have written a script for inserting data into database but stil face probs...plz help
by shevek (Beadle) on Oct 23, 2010 at 11:06 UTC |