http://www.perlmonks.org?node_id=358909

CB database tool (work in progress)

use warnings; use strict; use LWP::Simple; use DBI; my $data = ''; my $dbh = ''; my $url = 'http://www.perlmonks.org/?node_id=207304'; my $pat = qr{ <author>(.*?)<\/author>.*?<text>(.*?)<\/text> }xs; $dbh = DBI->connect( "dbi:SQLite:dbname=C:\\testdb", "", "" ); $data = get( $url ); while ($data =~ m/$pat/msg) { my ($auth, $text) = ($1, $2); for( $text ) { s/[ ]+/ /g; s/^\s+//; s/\s+$//; } printf "%s: %s\n\n" , $auth , $text; $dbh->do('insert into monks values(?,?)', undef, $auth, $text ); }
use warnings; use strict; use Switch; my $dna = 'atctcttttcgtctgctttggggtttgtcctataggcta'; my $base = ''; my @bases = (); my $a = ''; my $c = ''; my $g = ''; my $t = ''; my $err = 0; my $total = 0; calc_base( $dna ); sub calc_base { my ( $dna ) = @_; print 'Please enter a base to calculate: '; chomp( $base = <STDIN> ); @bases = split '', $dna; $total = length $dna; for( @bases ) { ++$a if /a/; ++$c if /c/; ++$g if /g/; ++$t if /t/; ++$err if /[^acgt]/; } switch ( $base ) { case "a" { printf "The amount of adenosine in the sequence is %. +2f%%", ( ($a/$total) * 100); } case "c" { printf "The amount of cytosine in the sequence is %.2 +f%%", ( ($c/$total) * 100); } case "g" { printf "The amount of guanine in the sequence is %.2f +%%", ( ($g/$total) * 100); } case "t" { printf "The amount of thymidine in the sequence is %. +2f%%", ( ($t/$total) * 100); } } }