Monks,

I need some help/suggestions. I have a .txt file that looks like this:
+ 192.168.89.1 acmeorp.acme.com |___ 21 File Transfer Protocol [Control] * + 192.168.31.3 ftp.acme.com |___ 21 File Transfer Protocol [Control] |___ 220 ftp.acme.com FTP server ready... * + 192.168.33.19 acmeftp.acme.com |___ 21 File Transfer Protocol [Control] |___ 220-acme Secure FTP Server.. WarFTPd 1.71.02 ( +Feb 14 2000) Ready.. (C)opyright 1996 - 2000 by Jarle (jgaa) Aase +- all righ * + 192.168.29.21 orcweb.acme.com |___ 21 File Transfer Protocol [Control] |___ 220 sandbox FTP server (Version 1.1.214.7 Thu Aug + 10 09:57:38 GMT 2000) ready... * + 192.168.11.22 commerce.acme.com |___ 21 File Transfer Protocol [Control] |___ 220 commerce Microsoft FTP Service (Version 4.0). +.. * + 192.168.19.24 webapp.acme.com |___ 21 File Transfer Protocol [Control] |___ 220 WEBAPP1PRI Microsoft FTP Service (Version 5.0 +)...
I want to be able to upload this file (via CGI.pm), parse it, and add it to a MySQL database (via DBI) which looks like this:
+-------------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------------+-------------+------+-----+---------+-------+ | ip | varchar(25) | YES | | NULL | | | svr_name | varchar(50) | YES | | NULL | | | port_num | varchar(6) | YES | | NULL | | | service | varchar(25) | YES | | NULL | | | description | varchar(50) | YES | | NULL | | +-------------+-------------+------+-----+---------+-------+
I can handle the CGI, DBI, and Mysql portions, but I'm looking for help on how to parse this file for adding it to the database. Does Perl have a way to convert a .txt file to a .csv file? I looked at Text::CSV, but that only seems to parse a csv file, not create one.

TIA,

Thanks,
Dru
Another satisfied monk.

In reply to Parse a .txt file for adding to a MySQL DB by dru145

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.