Hello monks,

I am trying to convert a txt file to csv which isn't really too difficult, however I'm not too sure how I would go about it with a text file that isn't pre formatted to having all of a clients info on one line, second client on second line, etc. This is how the txt file currently reads:

Jacobs, April 750.467.9582 quam.quis@sedhendrerit.org Mays, Martena 870.348.1974 sollicitudin@nonummyFusce.org McNeil, Brennan 289.527.6151 lobortis@nisl.com Sexton, Melvin 599.927.5337 in.felis@varius.com Blackburn, Prescott 661.589.1228 sed@egetlaoreetposuere.edu

I need to basically format the info in a csv file to read as a table with headers of Name, Phone and email. Each different client on a new row.

This is what I currently have as far as reading in the text file and writing the csv file. My problem is I have no idea how I would go about grabbing data into specific fields with the way the txt file is currently formatted.

use strict; use warnings; my $infile="clients.txt"; open my $in, "<", $infile or die $!; open my $out, ">" , "clients.csv" or die $!; my $client = <$in>; chomp($client);

Any help greatly appreciated.


In reply to converting txt to csv and formatting by csorrentini

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.