Hello Monks,
Please don't judge me too harshly as a perl newbie but I am a bit lost in the perl forest. I am attempting I/O on a tab delimited file which looks like this:
ISBN OCLC TITLE AUTHOR CALL_NUMBER
853694893 53123369 Transdermal and topical drug delivery from theory to clinical practice / Adrian Williams. "Williams, Adrian, 1963-" RM151 .W55 2003X 2003
471056693 "Pattern classification / Richard O. Duda, Peter E. Hart and David G. Stork." "Duda, Richard O." 006.4; D844; 2001
I've cobbled together code from some old threads but the parser is not pleased. I'm sure there are some elementary mistakes. Would you please help me clean it up?
Thanks,
Libmonk
#!/usr/bin/perl
use strict;
use warnings;
use IO::File;
use LWP::Simple;
## file's structure - tab delimited
# ISBN OCLC TITLE AUTHOR CALL_NUMBER
open (DATAFILE, "input.txt") or die "There is a problem opening the datafile.";
open (NEWFILE, "output.txt") or die "There is a problem opening the output file.";
while (<NEWFILE>) {
chomp;
my @fields = split(/\t/, $line); # splits tab separated fields - replace \t with \, \^ \|, whatever you need
# field names
$isbn = $fields[0];
$ocln = $fields1;
$title = $fields2;
$author = $fields3;
$call_number = $fields4;
}
foreach $line (<DATAFILE>)
{
$line =~ s/&+/&/;
($isbn, $ocln, $title, $author, $call_number) = split(/\t/, $line);
#$ISBN =~ /(^\d{10,13})/;
#$ISBN = $1;
print NEWFILE "<match>\n";
print NEWFILE "<title>";
print NEWFILE $title, "</title>\n";
print NEWFILE "<isbn>";
print NEWFILE $isbn, "</isbnr>\n";
print NEWFILE "<call_number>";
print NEWFILE $call_number,"</call_number>";
print NEWFILE "</match>\n";
}
close (DATAFILE);
close (NEWFILE);
In reply to input tab delimited file by libmonk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |