#!/usr/bin/perl


$n =1;

open (FILE, "classBooks.json");
while ($line = <FILE>) {
	chomp $line;
	if ($line =~ /"title"\s*:\s*"([^"]+)"/i) {
		$title = $1;
	}
	if ($line =~ /"first name"\s*:\s*"([^"]+)"/i) {
		$firstName = $1;
	}
	if ($line =~ /"last name"\s*:\s*"([^"]+)"/i) {
		$lastName = $1;
	}	
	
	if ($line =~ /\},/) {

		$books{$n}{"title"} 	= $title;
		$books{$n}{"firstName"} = $firstName;
		$books{$n}{"lastName"} 	= $lastName;
		$n++;
	}

}
close FILE;



foreach $bookNumber (keys %books) {
# 	foreach $data (keys %{$books{$bookNumber}}) {	
# 		print $books{$bookNumber}{$data} . "\n";
# 	}

	print qq+
	<book>
		<title>$books{$bookNumber}{"title"}</title>
		<author>$books{$bookNumber}{"first name"} $books{$bookNumber}{"last name"}</author>
	</book>
	
	+

}


