#/usr/local/perl-5.6.0/bin/perl -w #Hongyan Sun 10/11/2003 version1 # this program combine the table imageinformation.txt into seperate xml files # use imageinformation.txt as input tab delimited files. $inputDir = "./"; $outputDir = "./xmlwithImage/"; $file = "Imageinformation.txt"; $xmlfile = $ARGV[0]; opendir(SRC, "$inputDir")||die "Can't open dir $inputDir\n"; opendir(DEC, "$outputDir") || die "Can't open dir $outputDir\n"; open(FILE, "$inputDir$file") || die "Can't open file"."$inputDir$file"."\n"; $num_field = 0; #indecate how many fields current row has(3~4) while (){ #put one line(one row of table) into array of files chomp; push(@lines,$_); #print OUT $_; } close (FILE); open(FILE, "$inputDir$xmlfile")||die "Can't open file"."$inputDir$xmlfile"."\n"; while (){ #put one line(one row of table) into array of files chomp; push(@xmllines,$_); #print OUT $_; } close (FILE); open(OUT, ">$outputDir$xmlfile") || die "Can't open file".">$outputDir$xmlfile"."\n"; @images; $m=0; @fields; @Imagecharacter1; @Imagecharacter2; $num_field=0; foreach (@lines){ foreach (@fields = split "\t", $_){ $num_field++; }#end foreach fields $templines="$fields[1]"; #print "$templines\n"; if($templines eq $xmllines[5]){ # print "1+$xmllines[5]\n"; # print "2+$templines \n"; $Imagecharacter1[$m] = $fields[2]; if($fields[3] ne ''){ $Imagecharacter2[$m] = $fields[3]; }else{ $Imagecharacter2[$m] = "s"; } # print "$Imagecharacter2[$m] abcd \n"; $images[$m]=""; $m++; }#end if temp eq xmllines }#end for each lines for ($i =0; $i<@xmllines; $i++){ print OUT "$xmllines[$i]\n"; foreach(@xmlcharacter = split "\"", $xmllines[$i]){ #print "$xmlcharacter[0]\n"; #print "$xmllines[$j]\n"; } for($j =0; $j<@images; $j++){ if( $xmlcharacter[1] eq $Imagecharacter1[$j]){ #print "$temp[$j]\n"; print OUT "$images[$j]\n"; } if($xmlcharacter[1] eq $Imagecharacter2[$j]){ print OUT "$images[$j]\n"; } }#end for images }#end for xmllines # clear the buffer @files #while (@files){ # pop(@files); #} closedir(SRC); closedir(DEC); close(OUT);