l i n u x - u s e r s - g r o u p - o f - d a v i s
L U G O D
 
Next Meeting:
October 7: Social gathering
Next Installfest:
TBD
Latest News:
Aug. 18: Discounts to "Velocity" in NY; come to tonight's "Photography" talk
Page last updated:
2001 Dec 30 17:03

The following is an archive of a post made to our 'vox-tech mailing list' by one of its subscribers.

Report this post as spam:

(Enter your email address)
Re: [vox-tech] postgresql/perl question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [vox-tech] postgresql/perl question



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'");
}




LinkedIn
LUGOD Group on LinkedIn
Sign up for LUGOD event announcements
Your email address:
facebook
LUGOD Group on Facebook
'Like' LUGOD on Facebook:

Hosting provided by:
Sunset Systems
Sunset Systems offers preconfigured Linux systems, remote system administration and custom software development.

LUGOD: Linux Users' Group of Davis
PO Box 2082, Davis, CA 95617
Contact Us

LUGOD is a 501(c)7 non-profit organization
based in Davis, California
and serving the Sacramento area.
"Linux" is a trademark of Linus Torvalds.

Sponsored in part by:
Sunset Systems
Who graciously hosts our website & mailing lists!