Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I have a series of HTML frames. In one frame I am outputting a series of results with a JavaScript 2-D array. I need to send this data via email to a certain distribution of people so I was gonna try to write a cgi script in perl to do so. I'm new to Perl so I was curious to see if anyone had a better idea ( is this a no brainer or a foolish endeavor? ). All the freebee cgi scripts can't understand my 2-D array...they only send one column of data and seem to fail to iterate through all columns. Pardon the ignorance, but is Perl a good way to do this or should I stray elsewhere?

Replies are listed 'Best First'.
Re: Perl and CGI
by sachmet (Scribe) on Mar 24, 2001 at 00:54 UTC
    You could always do:
    use Net::SMTP; use Data::Dumper; $mdarray = [ [0,1,2], [3,4,5] ]; my $mail = Net::SMTP->new("smtp.server"); $mail->from('Some@from.addr'); $mail->to('your@addr.here'); $mail->data(); $mail->datasend("From: Some\@From.addr\n"); $mail->datasend("To: your\@to.addr\n"); $mail->datasend("Subject: Data from web site\n"); $mail->datasend("Date: " . scalar(localtime()) . "\n\n"); $mail->datasend(Dumper($mdarray)); $mail->dataend(); $mail->quit;
    Or, alternately, get rid of the use Data::Dumper, and change the Dumper line to:
    foreach my $row (@{$mdarray}) { $mail->datasend("data row: @{$row}"); }
    Or even yet:
    foreach my $row (@{$mdarray}) { $mail->datasend("item 1: $row->[0]\n"); ... }
    Any of those approaches should work.

    update: whoops! the remainder of the datasend got put into the from: field. Fixed correctly.

Re: Perl and CGI
by arturo (Vicar) on Mar 24, 2001 at 00:48 UTC

    Can Perl do it? Of course. Perl can do just about anything you'd want to do with data. If you come to this site asking "should I use Perl for this job?" the answer is almost always "YES!" =)

    I recommend having a good Perl book around, though, because you *will* have to learn some Perl to put a script to work. And after you learn Perl, if you're like most us, you'll stop doing other things ... >=)

    Philosophy can be made out of anything. Or less -- Jerry A. Fodor