I am using Text::CSV to read in data from a CSV file. this works well enough, but the output looks less than pretty.

Here is the perl code I'm using:

#!/usr/bin/perl use strict; use warnings; use Text::CSV; my $file = 'test.csv'; my $csv = Text::CSV->new(); open (CSV, "<", $file) or die $!; while (<CSV>) { if ($csv->parse($_)) { my @columns = $csv->fields(); print "@columns\n"; } else { my $err = $csv->error_input; print "Failed to parse line: $err"; } } close CSV;

Here is a sample of data from the CSV file:

Account,Login Name,Password,Web Site,Comments Google Docs,george123,F0oB@r,http://www.google.com/docs,The GoodleDocs + site Amazon,george123,fo0bA7,http://www.amazon.com,The Amazone Kindle site Apple,george123,mM_B39Aa,https://www.apple.com/accountmanagement,My Ap +ple account

When I use my perl script to parse this, here is what I get:

Account Login Name Password Web Site Comments Google Docs george123 F0oB@r http://www.google.com/docs The GoodleDocs + site Amazon george123 fo0bA7 http://www.amazon.com The Amazone Kindle site Apple george123 mM_B39Aa https://www.apple.com/accountmanagement My Ap +ple account

As you can see, the columns don't line up well to make it readable.

Here is what I'd like it to look like:

Account 	Login Name 	Password	Web Site 				Comments
Google Docs 	george123 	F0oB@r 		http://www.google.com/docs 		The GoodleDocs site
Amazon 		george123 	fo0bA7 		http://www.amazon.com/kindle 		The Amazone Kindle site
Apple 		george123 	mM_B39Aa	https://www.apple.com/accountmanagement My Apple account

I haven't been able to figure out how to get it formatted all purdy like it is above and would appreciate any help you could give


In reply to Formatting Output by jwalker1960

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.