Without even trying to understand what was required, a lot is already possible with DBD::CSV.
$ cat pm1072615.csv
Month,Zone,Replicate,SpeciesA,SpeciesB,SpeciesC
Sept,1,1,5,10,15
Sept,1,2,0,5,10
Sept,1,3,5,0,5
Sept,2,1,5,5,5
Sept,2,2,10,15,10
Sept,2,3,0,0,5
$ cat pm1072615.pl
#!/usr/bin/perl
use 5.14.2;
use warnings;
use DBI;
my $dbh = DBI->connect ("dbi:CSV:", undef, undef, {
f_ext => ".csv/r",
});
my $sth = $dbh->prepare (qq;
select month, zone, replicate, avg (speciesa)
from pm1072615
group by month,zone, replicate;
);
$sth->execute;
while (my $row = $sth->fetch) {
printf "%-5s %3d %3d %8.5f\n", @$row;
}
$ perl pm1072615.pl
Sept 2 1 5.00000
Sept 2 2 10.00000
Sept 1 1 5.00000
Sept 1 3 5.00000
Use of uninitialized value in printf at pm1072615.pl line 19.
Sept 1 2 0.00000
Use of uninitialized value in printf at pm1072615.pl line 19.
Sept 2 3 0.00000
$
Enjoy, Have FUN! H.Merijn
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.