<body>

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;

}

#print

foreach $line (<DATAFILE>)
{
$line =~ s/&+/&amp;/;
($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);

</body>

In reply to input tab delimited file by libmonk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.