How do I create a CSV file using Perl?

前端 未结 3 651
你的背包
你的背包 2020-12-10 01:32

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

3条回答
  •  有刺的猬
    2020-12-10 01:59

    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.

提交回复
热议问题