$new_guy has asked for the wisdom of the Perl Monks concerning the following question:
The file I am trying to convert is:#!/usr/bin/perl use strict; use warnings; use Text::CSV; my $file = 're-organized.txt'; my $csv = Text::CSV->new(); #now make a file for the ouput my $outputfile5 = "re-organized.csv"; if (! open(POS, ">>$outputfile5") ) { print "Cannot open file \"$outputfile5\" to write to!!\n\n +"; exit; } open (CSV, "<", $file) or die $!; while (<CSV>) { if ($csv->parse($_)) { my @columns = $csv->fields(); print POS "@columns\n"; } else { my $err = $csv->error_input; print "Failed to parse line: $err"; } } close CSV;
0 z z z z z z z z + z z z z z z z z z z z z z z z z + z - z z z z z z z z z z z z z z + z z z z z z z z z z z z z z z z z z + z z z z z z z z z z z z z z z z z z +z z z z z z z z z z z z z z z z z z z + z 0 z z z z z z - z + - z z z z z z - z z z z z + - z z - - z - z z z z + - z z z z z z z z - z z z + - z z z - - z - z z z z + z z z z z z z z z z z z z z z z z + - z z z z z - z z - z z z z + z z z z z z z z
I encounter a problem! The script does not separate the elements/values in each row into separate columns in the .csv spreadsheet. How can I resolve this so that I have each value in the rows in a separate column in the generted .csv file?
thanks
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Converting a text file to a csv file
by suhailck (Friar) on Sep 28, 2010 at 07:56 UTC | |
by $new_guy (Acolyte) on Sep 28, 2010 at 10:26 UTC | |
|
Re: Converting a text file to a csv file
by bart (Canon) on Sep 28, 2010 at 08:43 UTC | |
by $new_guy (Acolyte) on Sep 28, 2010 at 10:24 UTC |