in reply to Re: Exporting from flatfile database
in thread Exporting from flatfile database

Your script:
open IN, "infile.dat"; open OUT, ">data.csv"; while (<IN>) { chomp $_; my @fields = split(/|/, $_); my $newLine = join(",", @fields); print OUT "$newLine\n" } close IN; close OUT;
would corrupt the data with:
hi|I'm with GNU,Inc.|I need a comma in my title this|will|produce|,|to|many|fields
Using pipes to delimit data is a better idea (usually) because it is less common in data. There are also several modules to parse CSV. Incuding Text::CSV.

UPDATE: tilly has pointed out that Text::CSV_XS is a better solution than Text::CSV. I handles imbedded line endings in the data.

grep
grep> cd pub 
grep> more beer

Replies are listed 'Best First'.
Exporting .csv file to EXCEL
by naive (Novice) on Jan 23, 2002 at 12:50 UTC
    Hi, i am new to perl. Recently, i have encounter a problem and i need some advise from u guys. Hope u can help me. Anyone know how to export a .csv file into excel using perl ??? I can only write a prog. to enter some data into excel but cant seem to call out a .csv file into excel using perl. Thks in advance.