Hi.

I am currently in a position where I am having to learn Perl in the context of developing a website using Embperl. I am at a point where I have a few subroutines that I would like to try off-loading to a separate file and then including that file on pages where those subroutines are to be used.

I understand that creating a Perl module/package may be more desireable, but for the purposes of this topic, I am trying to figure out how to get 'do' to work. Feel free to make comments and recommendations as far as creating a package instead though because the more information I have while I learn, the better.

To test the basic functionality, I created two files. lib.pl and testlib.bhtml. In our environment, bhtml files are HTML files that contain Embperl code.

lib.pl:

sub libTest {
    $out=shift;
    return "libTest says \"".$out."\"";
}

1;

testlib.bhtml:

[! do "./lib.pl"; !][## I have tried lib.pl, "lib.pl", "./lib.pl", and ./lib.pl with the same result ##]
Output: "[+ libTest("test") +]"

When I try to load testlib.bhtml in the browser, I get the following error:
[31333]ERR: 24: Error in Perl code: Undefined subroutine &Embperl::__6::libTest called at /home/david/www/testlib.bhtml line 2.

Can anyone tell me what I may be doing wrong. Also, in the error code above, what is the significance of the string "::__6"? That "6" cycles (seemingly randomly) between 6, 7, and 2 as I continue to refresh the page.

Thanks in advance for any help!

Dave

Does anyone have any clue what I am doing wrong here? I can get it working by creating a module and using it, but the problem I have there is that Perl caches the module so it doesn't pick up on changes I make to it (e.g. adding a subroutine). So, I'm looking for a way to include subroutines from a single external file where my changes will take effect as soon as they are made.

Well, I still don't know what I was doing wrong above (it seems to me that it should have worked), but I managed to get it to work by using "do" like this:

do $epreq->component->cwd.'/lib.pl';
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.