Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

creating csv file with perl

Tags:

perl

I created csv file with this perl module Text::CSV_XS on windows:

Below a snippet of my code :

use Text::CSV_XS;

my @a =('ID','VALUE'); 


open my $OUTPUT,'>',"file.csv" or die "Can't able to open file.csv\n";

my $csv = Text::CSV_XS->new ({ binary => 1, eol => $/ });



$csv->print($OUTPUT,\@a);

this code generate a file.csv but when I try to open the file.csv with xls the xls write that this file is SYLK and can't know it could someone help why this csv can't open with xls?

like image 341
smith Avatar asked Nov 15 '11 18:11

smith


People also ask

What is CSV file in Perl?

Reading and processing text files is one of the common tasks done by Perl. For example, often you encounter a CSV file (where CSV stand for Comma-separated values) and you need to extract some information from there.

How do I skip the first line in a CSV file in Perl?

open FILE, "<$ARGV[0]"; my @file = <FILE>; splice(@file, 0, 1); Done. Now your @file array doesn't have the first line anymore.

How do I read a column from a CSV file in Perl?

To read a column from csv for this purpose I wrote this script: #!/usr/bin/perl -w use strict; use warnings; use Text::CSV; my$column_separator = qr/,/; my $column_number = "3"; my$file = "/home/Admin/Documents/new (copy).


1 Answers

This problem occurs when you open a text file or CSV file and the first two characters of the file are the uppercase letters "I" and "D"

"SYLK: File format is not valid" error message when you open file

like image 89
SAN Avatar answered Oct 19 '22 23:10

SAN