#!/usr/local/bin/perl
use strict;
my @books;
my @authors;
my $bookfilename = "book.data";
my $authorfilename = "author.data";
if(!open(INPUT,"<$bookfilename"))
{
print "Can't open $bookfilename\n";
die;
}
my $bookcount = 1;
my $line;
while($line = )
{
chomp $line;
my $word;
my @splitline = split(/\s/, $line);
print "@splitline\n";
@books[$bookcount].push(@splitline);
my $size = @books[$bookcount];
print "books: @books\n";
print "size: $size\n";
if($size != 6){
print "too many tokens at line $bookcount\n";
die;
}
if($books[$bookcount][0] =~ /\W|"_"/ || length($books[$bookcount][0])!=4){
print "error in book code $books[$bookcount][0] at line $bookcount.\n";
die;
}
if($books[$bookcount][1]=~ /\W/ || length($books[$bookcount][1])>30){
print "error in book title $books[$bookcount][1] at line $bookcount.\n";
die;
}
if($books[$bookcount][2] =~ /[^A-Z]/ || length($books[$bookcount][2])>3){
print "error in pub code $books[$bookcount][2] at line $bookcount.\n";
die;
}
if($books[$bookcount][3] =~/[^A-Z]/ || length($books[$bookcount][3])>3){
print "error in type $books[$bookcount][3] at line $bookcount.\n";
die;
}
if($books[$bookcount][4] =~/^[^\d?\d?\d?\d?\.\d\d]$/ || length($books[$bookcount][4])>7)
{
print "error in price $books[$bookcount][4] at line $bookcount.\n";
die;
}
if($books[$bookcount][5] =~ /[^Y]|[^N]/ ||length($books[$bookcount][5])>1)
{
print "error in paperback flag $books[$bookcount][5] at line $bookcount.\n";
die;
}
$bookcount++;
}
close(INPUT);
if(!open(INPUT,"<$authorfilename"))
{
print "opening $authorfilename failed.\n";
die;
}
my $authorcount = 1;
while($line = )
{
chomp $line;
$authors[$authorcount] = split(/\s/, $line);
my $size = @authors[$authorcount];
if($size != 3){
print "too many tokens at line $authorcount.\n";
die;
}
if($authors[$authorcount][0] =~ /\D/ || length ($authors[$authorcount][0]) > 5)
{
print "error in author number $authors[$authorcount][0] at line $authorcount.\n";
die;
}
if($authors[$authorcount][1] =~ /[^A-z]/ || length($authors[$authorcount][1]) >30)
{
print "error in author last name $authors[$authorcount][1] at line $authorcount.\n";
die;
}
if($authors[$authorcount][2] =~/[^A-z]/ || length($authors[$authorcount][1])>30)
{
print "error in author first name $authors[$authorcount][2] at line $authorcount.\n";
die;
}
$authorcount++;
}
close(INPUT);