Author: Kai Lübke
Date: 04:23:03 10/19/98
Go up one level in this thread
On October 19, 1998 at 06:25:54, Peter Herttrich wrote:
>Howdy
>
>
>Look at this PGN-Header and tell me, if the first line
>is correct or not:
>
>[Event "Ch "Trade Unions""]
>[Site "Leningrad (Russia)"]
>[Date "1938.??.??"]
>[Round "?"]
>[White "Bastrikov Georgy"]
>[Black "Panov Vasily (RUS)"]
>[Result "1-0"]
>[ECO "A56/11"]
>
>If the line is ok, then I and David Barnes have a problem.
>If not, which stupid program generates this lines?
>I have found thousends of them, and its nearly unimpossible,
>to get rid of the ".
I'm not sure if the format is correct, but it's not too hard to get rid of the
extra quotes - if you know how to write Perl scripts (the #1 when it comes to
parsing strings). :)
Here's how it works:
--------------------------------------------------------------
#!/usr/bin/perl
# open input and output file (omitted)
# do a "while" loop over the lines of the input file (omitted)
# read <LINE> into $line (omitted)
# do the following only if the Event line was read:
if ($line=~"Event"){
# split line by quotation marks
@temp="";
@temp=split(/\"/,$line);
# let's see if we have 2 or 4 quote marks
# if we have 4, it's one of the "problem lines":
if ($#temp==4){
# join the components between the outer quote marks
$temp2=join(/ /,$temp[1],$temp[2]);
# join the line back
$line= join(/\"/,$temp[0],$temp2,$temp[3]);
} #end if
} #end if
# write $line to output file (omitted)
# end while loop (omitted)
# close files (omitted)
------------------------------------------------------------------------
This script needs some testing and maybe a clean-up of the $temp2 (spurious
leading/trailing white spaces may occur?).
---
Shep
This page took 0 seconds to execute
Last modified: Thu, 15 Apr 21 08:11:13 -0700
Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.