#Perl convertor - changes href .mol to .mol.xml
#!/usr/local/bin/perl 

###########################
##   Read in the input   ##
###########################

# make sure input file is defined

if (1*@ARGV==0) { 
	print "No filename supplied.";
}

else {


# locate the file and define the output file

$INPUT_FILE = "@ARGV[0]";
$OUTPUT_FILE = "hack"."@ARGV[0]";

# make sure input file is present

if (!-e $INPUT_FILE) {
	print "The file $INPUT_FILE doesn't exist.";
}

else {


# read the input file into @array

open(INPUT_FILE);
@array = <INPUT_FILE>;
close(INPUT_FILE);

foreach (@array) {

$wholefile = $wholefile.$_;

}

# entire input file is now contained 
# in scalar variable $wholefile

# get the arguments and put them in variables
	$file = @ARGV[0];
	
############################
##   Sort out the input   ##
############################

# sort out the href

$wholefile =~ s/<a\s+href="([^"]+)\.mol"/<a href="\1.mol.xml"/g ;
$wholefile =~ s/<A\s+HREF="([^"]+)\.mol"/<a href="\1.mol.xml"/g ;

# write the final version to file

open(OUTPUT_FILE,">$OUTPUT_FILE"); 
print OUTPUT_FILE ($wholefile);
close(OUTPUT_FILE)
#

}
}