jwalker1960 has asked for the wisdom of the Perl Monks concerning the following question:
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Formatting Output
by toolic (Bishop) on Oct 11, 2012 at 17:36 UTC | |
by frozenwithjoy (Priest) on Oct 11, 2012 at 18:02 UTC | |
by Anonymous Monk on Oct 12, 2012 at 00:32 UTC | |
by frozenwithjoy (Priest) on Oct 12, 2012 at 01:05 UTC | |
by Anonymous Monk on Oct 12, 2012 at 01:39 UTC | |
|
Re: Formatting Output
by kcott (Archbishop) on Oct 12, 2012 at 09:04 UTC | |
by jwalker1960 (Initiate) on Oct 18, 2012 at 21:11 UTC | |
by kcott (Archbishop) on Oct 19, 2012 at 10:33 UTC |