Hi follow wisdom seekers!

Still learning Perl and loving it...

Any help would be greatly appreciated! Tnx!

I have a program that arranges the content of a text file into rows so that I could import it to Access.

But I want it to read the content of the whole directory instead of letting the user enter a filename.

Then stores it to one location. Or maybe in a sql or mysql database.

So, the text file contents in the directory becomes record entries.

Here's the sample data:
text1.txt
<NAME>MARK\n<AGE>27\n<ADDRESS>PHILIPPINES\n
text2.txt
<NAME>Anthony\n<AGE>26\n<ADDRESS>UNITED KINGDOM\n

Here's the code
use strict; use warnings; my $SOURCEFILE; my $TARGETFILE; my $REPORTFILE; my $converted; my $discarded; my $holder; my $titleid; print "Enter filename to convert: "; chomp($SOURCEFILE = <STDIN>); print "Save to:"; chomp($TARGETFILE =<STDIN>); print "Save Conversion Report to:"; chomp($REPORTFILE =<STDIN>); open SOURCEFILE, '<', $SOURCEFILE or die "Can't open $SOURCEFILE: $!"; open TARGETFILE, '>', $TARGETFILE or die "Can't open $TARGETFILE: $!"; open REPORTFILE, '>', $REPORTFILE or die "Can't open $REPORTFILE: $!"; $converted=0; $discarded=0; sub reporting { print TARGETFILE $holder; print REPORTFILE " -> "; print REPORTFILE $holder; $converted++; } #Evaluate per line foreach my $line (<SOURCEFILE>) { if ($line =~ /<NAME>(\w+)/) { print REPORTFILE $line; #saves original value to repor +tfile $line =~ s/<NAME>/|/; $line =~ s/\n//g; $holder = $line; reporting; } elsif ($line =~ /<AGE>(\w+)/) { print REPORTFILE $line; $line =~ s/<AGE>/|/; $line =~ s/\n//g; $holder = $line; reporting; } elsif ($line =~ /<ADDRESS>(\w+)/) { print REPORTFILE $line; $line =~ s/<ADDRESS>/|/; $line =~ s/\n//g; $holder = $line; reporting; } elsif ($line =~ /<PHONE>(\w+)/) { $discarded++; print REPORTFILE "<xx> "; print REPORTFILE $line; } } print TARGETFILE "^\n"; # eof line marker print REPORTFILE "No. of fields Converted: "; print REPORTFILE $converted, "\n"; print REPORTFILE "No. of fields Discarded: "; print REPORTFILE $discarded, "\n"; close SOURCEFILE or die "Can't close: $!"; close TARGETFILE or die "Can't close: $!"; close REPORTFILE or die "Can't close: $!";

In reply to convert directory content to dbf by oblate kramrdc

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.