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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |