I'm trying to figure out how to populate the databse with content from the Read_File sub. And how can i integrate the Scan_File sub into my program so that instead of those print line in the Read_File sub it populate the databse.#!/perl/bin/perl use strict; use File::Copy; # Used to buffer files-to-send use DBI; use Switch; #Main# #Scan File# my $scan_dir = "C:\\Log"; my $error_file = "error_log"; my $filename; my $data; my @name; my @info; opendir DIR, $scan_dir; open( ERROR, ">>$error_file" ); # Search cache directory for csv files while ( $filename = readdir(DIR) ) { if ( $filename =~ /\.txt$/i ) { $data = Read_File( $scan_dir, $filename ); } } close(DIR); close(ERROR); #Read File# sub Read_File { my ( $scan_dir, $file_name ) = @_; print "Read file $scan_dir\\$file_name\n"; open (CVS, ">>Test.txt") or die "Cannot write CVS\n "; open( FILEREAD, "$scan_dir\\$file_name" ) or die "cannot open $fil +e_name\n"; my $Test = <FILEREAD>; my @Content = split( / /, $Test ); my ($EquipmentID, $Chamber, @LotID, $Recipe, $AlarmType, $Sensor, +$Signal_Level, $Alarm_Upper_Limit, $Alarm_Lower_Limit); my ($UserCode, $Code, $Date_Submited, $Time_Submited); my $number; my (@array, @Comment); my $count; my $regex; for ( $number = 0 ; $number <= $#Content ; $number++ ) { @array= split(/=/,$Content[$number] ); switch ($array[0]) { case (/EQPID/i) { print "EQPID = $array[1]\n"; $Chamber = substr ($array[1], -1, 1); switch ($Chamber){ case (/A/i) {print "Chamber 1\n";} case (/B/i) {print "Chamber 2\n";} case (/C/i) {print "Chamber 3\n";} case (/D/i) {print "Chamber 4\n";} } } case (/AlarmType/i) {print "AlarmType=$array[1]\n";} case (/LotID/i) { print "$array[1]\n"; @LotID = split( /-/, $array[1] ); print "LotID = $LotID[0]\n"; print "Wafer_Flow = $LotID[1]-$LotID[2]\n"; } case (/Comment/i) { @Comment = split( /,/, $array[1] ); for ($count = 0; $count<=$#Comment; $count++) { if ($count==1) { print "Sensor = $Comment[$count]\n"; + } elsif ($count==2) { print "Signal_level = $Comment[$count]\n"; } elsif ($count==3) { print "AUL = $Comment[$count]\n"; } elsif ($count==4) { print "ALL = $Comment[$count]\n"; } elsif ($count==5) { print "Recipe = $Comment[$count]\n"; } elsif ($count==6) { print "Wafer_slot = $Comment[$count]\n"; } elsif ($count==7) { print "Step_Value = $Comment[$count]\n"; } } } case (/Code/i) {print "Code = $array[1]\n";} case (/UserCode/i) {print "Code = $array[1]\n";} } } } sub Scan_File { my $dbh = DBI->connect('DBI:ODBC:mwalarm') or die "Couldn't connect to database: " . DBI->errstr; my $sql = "INSERT INTO Alarm_Info(EquipmentID, Chamber, LotID, Wafer_Flow, R +ecipe, Wafer Slot, AlarmType, Sensor, Signal_level, Alarm_Upper_Limit, Alarm_Lower_Limit, UserCode, Code +, Date_Submited, Time_Submited, False Positive) VALUES () "; my $sth = $dbh->prepare($sql) or die "Couldn't prepare statement: " . $dbh->errstr; $sth->execute() or die "cant execute" . $dbh->errstr; $sth->finish; }
In reply to Parsing Script by phimtau123
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |