<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">#!/usr/bin/perl



use DBI;

sub strip{
	$temp = @_[1];
	if ( @_[0] =~ /$temp *= *{([^}]+)}/s ) {
		#print "$temp={$1}\n";
		@col_name =( @col_name ,$COLNAME_HASH{@_[1]});
		@col_val = ( @col_val, "\"$1\"");
	}
}

sub split_string{
	$s = @_[0];
#	$s =~ /(ARTICLE|INPROCEEDINGS|INBOOK|BOOK|TECHREPORT|MISC|UNPUBLISHED){([\w -]+),/;
	$s =~ /@([A-Z]+){([\w-]+),/s ;
	#print "type:$1\n";
	@col_name = ("REFTYPE","KEYWORD");
	@col_val = ("\"$1\"","\"$2\"");


						&amp;strip($s, 'TITLE');
						&amp;strip($s,'KEY');
						&amp;strip($s,'BOOKTITLE');
						&amp;strip($s,'JOURNAL');
						&amp;strip($s,'VOLUME');
						&amp;strip($s,'NUMBER');
						&amp;strip($s,'PAGES');
						&amp;strip($s,'YEAR');
						&amp;strip($s,'MONTH');
						&amp;strip($s,'CHAPTER');
						&amp;strip($s,'PUBLISHER');
						if ($s =~ /AUTHOR={+([^}]+)}/s ){
						$authors = $1;
						$i=1;
						while ( $authors =~ s/([^}]+?)\band\b// ){
							print "******8$authors : $1\n";
							@col_name = ( @col_name , "AUTHOR$i");
							@col_val = ( @col_val, "\"$1\"");
							$i++;
						}
							@col_name = ( @col_name , "AUTHOR$i");
							@col_val = ( @col_val, "\"$authors\"");
		#				print "author$i $authors\n";
						}
						&amp;strip($s,'INSTITUTION');
						&amp;strip($s,'NOTE');

						$cmd = "INSERT INTO $TABLE_NAME ( ".
						(join "," ,@col_name) .
						" ) VALUES (". (join ',', @col_val ).");";
						if ( @col_val != () ) {
						print "$cmd\n\n";
						$sth= $dbh-&gt;prepare($cmd);
						$sth-&gt;execute();
						}
						

							
						
}


%COLNAME_HASH=('REFTYPE','REFTYPE',
				'KEYWORD', 'KEYWORD',
				'TITLE','TITLE',
				'KEY','REFKEY',
				'BOOKTITLE','BOOKTITLE',
				'JOURNAL','JOURNAL',
				'VOLUME','VOLUME',
				'NUMBER','NUM',		# this is the only reason I use
									# this hash
				'PAGES','PAGES',
				'YEAR','YEAR',
				'MONTH','MONTH',
				'CHAPTER','CHAPTER',
				'PUBLISHER','PUBLISHER',
				'AUTHOR1','AUTHOR1',
				'AUTHOR2','AUTHOR2',
				'AUTHOR3','AUTHOR3',
				'AUTHOR4','AUTHOR4',
				'AUTHOR5','AUTHOR5',
				'AUTHOR6','AUTHOR6',
				'INSTITUTION','INSTITUTION',
				'NOTE','NOTE',
				'HOWPUBLISHED','HOW_PUBLISHED'
				);
				


$TABLE_NAME="refs";
$DATABASE="yangyang_ref";

$dbh = DBI-&gt;connect("DBI:mysql:$DATABASE");


while(&lt;&gt;){
	my $temp;
	if ( /@/ ){
		$temp = $_;
		&amp;split_string( $string);
		$string = $temp;
	}else{
		$string .= $_;
	}
}

split_string( $string );


</pre></body></html>