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

frankdew has asked for the wisdom of the Perl Monks concerning the following question:

Hi all, I've made a perl script that installs PostgreSQL, DBI and then DBD::Pg. Its does install Postgre and DBI correctly, but fails to install DBD::Pg. If I run the script a second time, it does install DBD::Pg correctly. I just dont understand why.
I'm running the script in sudo mode... here is a snippet from my code:
system("sudo aptitude update"); if ( $? == -1 ) { print "sudo aptitude update failed: $!\n"; exit; } system("sudo aptitude install postgresql-server-dev-8.3"); if ( $? == -1 ) { print "sudo aptitude install postgresql-server-dev-8.3 failed: $!\n" +; exit; } use CPAN; CPAN::Shell->install("DBI"); CPAN::Shell->install("DBD::Pg"); ----------
The first time, it fails with the following message:
Running make test
PGINITDB="/usr/lib/postgresql/8.3/bin/initdb" PERL_DL_NONLAZY=1 /usr/bin/perl "-MExtUtils::Command::MM" "-e" "test_harness(0, 'blib/lib', 'blib/arch')" t/*.t
t/00-signature......skipped
        all skipped: Set the environment variable TEST_SIGNATURE to enable this test
t/00basic...........NOK 2
#   Failed test 'use DBD::Pg;
#   at t/00basic.t line 14.
#     Tried to use 'DBD::Pg'.
#     Error:  DBD::Pg object version undef does not match bootstrap parameter 2.15.1 at /usr/lib/perl/5.8/DynaLoader.pm line 245.
# Compilation failed in require at (eval 7) line 2.
# BEGIN failed--compilation aborted at (eval 7) line 2.
FAILED--Further testing stopped: Cannot continue without DBD::Pg
make: *** test_dynamic Error 9
  /usr/bin/make test -- NOT OK
Running make install
  make test had returned bad status, won't install without force.


Can somebody help me solve this problem ? I would like to understand why it works on the second run. Thank you for your help monks!