in reply to Where are those memory leaks?

Well - memory leaks are are often pesky little beasties to catch!

I would guess that the most likely candidate is the DBH - but you dont show exactly how you are opening the DBH. Make sure that PrintError and RaiseError are on. If necessary, put your DBH into trace mode.

Also, you say that it runs fine, but gradually consumes memory until the machine expires - yet your example does not really show any sort of long-running loop? Perhaps the issue is actually in the loop construction?

Self referencing and circular object references can also cause issues - but OOh - your example does not indicate that sort of style.

In my experience, using undef to force vars out of scope is usually a mistake. There are some malloc cleanup bugs in Perls built with libc2.2.5 that can cause garbage collection to run for long periods.

and because I couldn't resist, here is Another Way - there are no doubt even More Ways to remove intermediate vars. :)

#!/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();

Oh - and did I mention perl -w and strict? Essentials! As an aside, your example only counts uppercase letters, and no other chars - I guess that you are counting on the quality of the input data.

Regards

Jeff