#!usr/bin/perl open LINKFILE, "linksource.dat" || die "no such file here"; while () { #memorize title, then url; my ($title) = /title=(".*?")/; ($title) =~ s/"/'/g; ($title) =~ s/^\s+//g; ($title) =~ s/\s+$//g; my ($url) = /(component.*")/; ($url) = '"/' . $url; ($url) =~ s/"/'/; my $match = 0; open SQL, "mark.sql"; while () { @fields = split /,/ , $_ ; foreach $i(0 .. $#fields) { s/^\s+//, s/\s+$// for $fields[$i]; } print "\$fields[2]:|$fields[2]| \$title:|$title| \n" if ($title eq "'Alternative Reds'");# monitor - stops after first A R hit?? next unless ($fields[2] eq $title); #skip it if it doesnt match next if ($fields[4] eq "'separator'"); #skip it if its not an URL push @used, $fields[0]; ($fields[3] = $url) if ($fields[2] eq $title); my $sqlout = join "," , @fields; open NEWFILE , ">>newsql.sql"; print NEWFILE "$sqlout \n"; close NEWFILE; last; } # finished going through the SQL } #finished cycling through linkfile close SQL; close LINKFILE; #Now go through each record, check to see if the index field matches the used array, and if not, write the record open SQL, "mark.sql"; while (){ @fields = split /,/ , $_ ; #compare first record element with the used array foreach (@used) { next if $fields[0] eq $_; # if the record has been used, dont use it again print "\$used:|$_| \$fields[0]:|$fields[0]| \n"; #monitor my $sqlout = join "," , @fields; open NEWFILE , ">>newsql.sql"; print NEWFILE "$sqlout"; push @used, $fields[0]; close NEWFILE; last; } }