Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I create a CSV file using Perl?

Tags:

csv

perl

I want to create a CSV file using Perl and write some data to it. Is there any way to do that?


1 Answers

You could use Class:CSV.

use Class::CSV;

my $csv = Class::CSV->new(
  fields         => [qw/userid username/]
);

$csv->add_line([2063, 'testuser']);
$csv->add_line({
  userid   => 2064,
  username => 'testuser2'
});

$csv->print();

# 2063,testuser
# 2064,testuser2

Edit: For more libraries, you can search CPAN.


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!