On Tue, 17 April 2001, Peter Jay Salzman wrote:
>
> hey all,
>
> can somebody send me a functional "hello, world" type program in perl
> that uses postgresql? maybe something that demonstrates storing a piece
> of datum and retrieving a piece of datum.
>
> thx!
> pete
Here is a simple script using the Pg module, select, and update.
#!/usr/bin/perl
#
# n_counter.pl grabs name and sequence fields from the sagres:plasmids db and counts
the number
# of "n"s.
#
#
#
use Pg;
$conn = Pg::connectdb("dbname=sagres port=5432");
$result = $conn->exec("SELECT name,sequence,orientation FROM plasmids ORDER BY name");
|| die $conn->errorMessage unless PGRES_COMMAND_OK eq $result->resultStatus;
while (@row = $result->fetchrow){
%count = ();
$name = $row[0];
$sequence = $row[1];
$orientation = $row[2];
$sequence =~ tr/A-Z/a-z/;
$test = $sequence;
if ($test =~ /error/){
$update = $conn->exec("UPDATE plasmids SET n = '0' WHERE name = '$name'
and orientation = '$orientation'");
next;
}
@sequence_array = split //, $sequence;
foreach $letter (@sequence_array){
$count{$letter} = $count{$letter} + 1;
}
$update = $conn->exec("UPDATE plasmids SET n = '$count{n}' WHERE name = '$name'
and orientation = '$orientation'");
}