How to write/output a .csv file with Perl?

Can someone please show me (preferably with a small script/source code) how I can:

  1. Write the following 2 lines:

sitepoint, 2, 7
google, 4, 3

  1. and output this file as a .csv in the current directory (i.e the same directory in which this script is found)

Anyone? Any help is highly appreciated. TIA!

open (FH, “>file.csv”) or die “$!”;
print FH "sitepoint, 2, 7
"
print FH "google, 4, 3
";
close(FH);

Hi KevinR, thanks for your effort. Now my source is:

#!/usr/bin/perl

use CGI qw(:standard);
use DBI;
use DBD::CSV;

open (FH, “>>file.csv”) or die “$!”;
print FH "sitepoint, 2, 7
";
print FH "google, 4, 3
";
close(FH);

Ok, got it working now. Thanks a million!

Now that I got the writing of the file worked out, I can’t seem to write a certain cookie’s value:

#!/usr/bin/perl -w

use CGI qw(:standard);

#my $q = new CGI;
#my $firstname = $q->param(‘$firstname’);

if($q->cookie(“firstname”) eq “”)
{
print redirect(“http://localhost”);
}

else
{
open (FH, “>>file.csv”) or die “$!”;

print FH "sitepoint, 2, 7
";
print FH “cookie(‘firstname’)”;
close(FH);

print redirect(“…/qn.htm”);
}