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

Hi monks,

I'm trying to find out more about how the perl function 'do' works.
I'm aware that in almost all cases it's better to 'use', but please bear with me...
If I have a cgi script with the following:
do 'loation/to/code.pl';
and the code looks like such:
warn 'this is a warning';
everything works fine.
However with the following setup, it doesnt print the warning the the http error log...
Script:
do 'location/to/code.pl';
code.pl:
do 'location/to/another/code.pl';
another/code.pl
warn 'this is a warning from another code";
Can anyone explain this to me please?

Cheers,
Reagen

Big Update: I've discovered that the problem is not being caused by the do code, but because one of the blocks of code is forking into the background.
I'm still interested to know what is going on, ie. how i can see the warnings, but I'm not sure now what route to take.
Should I mark this question as mute and open a new one or continue with this one?
Cheers.

Replies are listed 'Best First'.
Re: behaviour of do
by revdiablo (Prior) on Apr 14, 2006 at 02:22 UTC

    I can't reproduce your behavior. It seems to Work For Me:

    $ cat one.pl #!/usr/bin/perl do 'two.pl'; $ cat two.pl #!/usr/bin/perl warn "Oops"; do "three.pl"; $ cat three.pl #!/usr/bin/perl warn "Poops"; $ perl one.pl Oops at two.pl line 2. Poops at three.pl line 2.
      yeah, thanks revdiablo.

      I just did the same test with the same results as you.
      Does each bit of 'do' code need to return true, do you know?
        perldoc -f do