Hi Folks
$DBI::VERSION = "1.609"
perl, v5.8.8 built for x86_64-linux-thread-multi
SHELL=/bin/tcsh
I'm not sure if this should be considered a bug in DBI or elsewhere, but it has
unpleasant consequences. Somewhere in the bowels of DBI, SIGPIPE gets set to
'IGNORE'. It remains in this state after disconnect(). If you then launch a
second script using backticks and this script contains a line like
my $first_line = `grep -v '#' $filename|head -n 1`; # to get the first
non-comment line
the shell which is invoked inherits the SIGPIPE = 'IGNORE' state. This causes a
grep: writing output: Broken pipe
error as the grep tries to write to the head process which has exited.
It took me a while to work this out because of the way perl populates the %SIG
hash. It appears it only populates it once from the system when it is first used
in the script. If you run the script below with the first print statement
commented out you get
connected to dk_funcgen_classify_59_MEF
SIGPIPE=IGNORE
If you uncomment the first print statement you get
SIGPIPE=UNDEF
connected to dk_funcgen_classify_59_MEF
SIGPIPE=UNDEF
However, behind the scenes, something has changed SIGPIPE to IGNORE and the %SIG
hash has not been updated.
(my workaround is to explicitly reset SIGPIPE to 'DEFAULT' in the second script)
cheers
Damian
#!/software/bin/perl -w
use strict;
use DBI;
use Env;
my($user, $password, $driver, $host, $port);
my $enc_db = 'dk_funcgen_classify_59_MEF';
&config;
#print "SIGPIPE=".( ($SIG{PIPE})? $SIG{PIPE}:'UNDEF')."\n";
my $dbh = &make_contact($enc_db);
$dbh->disconnect;
print "SIGPIPE=".( ($SIG{PIPE})? $SIG{PIPE}:'UNDEF')."\n";
exit;
#########################################################################
sub config{
($user = $ENV{'ENSFGUSER'}) or return(0); # ecs1dadmin
($password = $ENV{'ENSFGPWD'}) or return(0); #
($host = $ENV{'ENSFGHOST'}) or return(0); #localhost
($port = $ENV{'ENSFGPORT'}) or return(0); #3360
($driver = $ENV{'ENSFGDRIVER'}) or return(0); #mysql
}
sub make_contact{
my $db = shift;
unless($driver && $db && $host && $port && $user){
&err("DB connection parameters not set");
exit(1);
}
# hook up with the server
my $dsn =
"DBI:$driver:database=$db;host=$host;port=$port;mysql_local_infile=1";
my $dbh = DBI->connect("$dsn","$user",$password, {RaiseError => 0});
if ($dbh){
print STDERR ("connected to $db\n");
}else{
&err("failed to connect to database $db");
exit(1);
}
return $dbh;
}
sub err{
print STDERR "$_[0]\n";
}
--
Damian Keefe PhD dke...@ebi.ac.uk European Bioinformatics Institute,
+44 (0)1223 49 4649 Wellcome Trust Genome Campus, Hinxton
+44 (0)1223 49 4468 (fax) Cambridgeshire CB10 1SD, UK