#!/usr/local/bin/perl -w use strict; use DBI; my @ids = @ARGV; die "no ids specified" unless scalar @ids; open (OUTPUT, ">>./output.txt") or die "Cannot open the output file: $!"; my $dbh; my $sql = "select long_string from mytable where id=?"; { my ( $dsn, $user, $password ) = ( "mydsn", "myuser", "mypassword", ); $dbh = DBI->connect( $dsn, $user, $password, {RaiseError => 1, AutoCommit => 0, PrintError => 1} ); die "DB Connect failed: DSN='$dsn' User='$user' Error='$DBI::errstr'" unless $dbh; } my $sth = $dbh->prepare($sql); my %count; my @zeros = (0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0); foreach my $id (@ids) { my $long_string = uc($dbh->selectrow_array($sth,{},$id)); @count{'A'..'Z'} = @zeros; for my $i ( 0 .. length($long_string)-1 ) { $count{substr($long_string,$i,1)}++; } print OUTPUT join("\t", ($id, @count{'A'..'Z'})), "\n"; } close (OUTPUT) or die "Cannot close the output file: $!"; $dbh->disconnect();