I think the answer is that both the modules where the BEGINS are called
twice have "use" in them. "use" means "BEGIN {require Module}", so BEGIN is
being called once when the module is entered, and once when it is used. 

Rob


At 02:39 PM 3/8/01 +0000, Leo wrote:
>Hi folks, got an odd one for you:
>
>Why is Dprof saying my LTest::BEGIN and mail::BEGIN
>are running twice ?
>
>%Time ExclSec CumulS #Calls sec/call Csec/c  Name
> 33.4   0.010  0.010      2   0.0050 0.0050  main::BEGIN    <----- ?
> 0.00   0.000 -0.000      1   0.0000      -  strict::import
> 0.00   0.000 -0.000      1   0.0000      -  strict::bits
> 0.00   0.000 -0.000      2   0.0000      -  LTest::BEGIN   <----- ?
> 0.00   0.000 -0.000      1   0.0000      -  Test2::BEGIN
>
>I've actually got this problem but magnified in a larger
>project which I'm trying to find a memory leak in.. I don't now
>if this is related (BEGIN being run 4 to 17 times! in different
>packages). 
>
>Is this my code, my not understanding Dprof or something else ?
>
>perl -v
>This is perl, v5.6.0 built for i386-linux
>
>test.pl
>-------
>#!/usr/bin/perl
>use strict;
>use LTest;
>
>package LTest;
>
>BEGIN {
>       use Test2;
>        warn "Test is beginning\n";
>}
>
>print "Here\n";
>
>1;
>
>package Test2;
>
>BEGIN {
>        warn "Test2 is beginning\n";
>}
>
>1;
>
>
>Oh, running this code gives:
>
>>./test.pl
>Test2 is beginning
>Test is beginning
>Here
>
>Making is even wierder! As 'Test is..' only
>prints once.
>
>Any help is much appreciated.
>
>Cheers
>
>Leo
>
>

--
Robert Price - Technical Manager - EMAP Digital Travel  | Tel: 0207 3092711
Priory Court, 30-32 Farringdon Lane, London, EC1R 3AW   | Fax: 0207 3092718

Reply via email to