in reply to Re: Re: a simple include....
in thread a simple include....

This error is due to the fact that you have strictures in use when including your file which unfortunately does not conply with strict. The 'simple' option is simple to turn off strictures when you're including the file
## effects of 'no strict' limited to the anonymous blocko { no strict; require "./inc.pl"; }
It's a little fiddly I admit, but no more fiddly than a script that doesn't conform to strict (it really does make your life easier).
HTH

_________
broquaint

Replies are listed 'Best First'.
Re: Re: Re: Re: a simple include....
by pcouderc (Monk) on Apr 30, 2003 at 14:38 UTC
    1- I understand from your answer that there is no equivalent of a "simple" include
    2- I have tried do declare
    package main;
    in both main.pl and inc.pl. It would oblige me to declare $main::Sousprogramme for all the variables of my main.pl. I have done that but I get more errors in a
    $main::cursor = ($main::dbh)->prepare("Select...");

    Database handle destroyed without explicit disconnect at /var/www/tools/crm/main.pl line 16.
    Wed Apr 30 15:59:34 2003 error Can't call method "prepare" on an undefined value at /var/www/tools/crm/main.pl line 44.
    This becomes complicated when I was looking for a "simple" include....
      I understand from your answer that there is no equivalent of a "simple" include
      There is, and it's require. Your requirements are more complex however, precluding one from any simple answer.

      Firstly package main is only necessary to explicitly declare that you are in main's namespace, which all code is by default. So unless you have other package declarations it will be unncessary in your code.

      Secondly, $main::dbh has not beeen assigned anywhere (or was defined somewhere, and undefined at a later point) which is why you get that second error message. Note that lexical variables are not the same as package variables, so if you have declared my $dbh in inc.pl then it will be undefined in main.pl (and does not exist as $main::dbh which is a package variable).

      As for the first error message I imagine it is due to the fact you have declared $dbh as a lexical variable in inc.pl and it is falling out of scope which will call it's DESTROY method (destructor) and thereby trigger said error message as there has been no explicit disconnect.
      HTH

      _________
      broquaint

        Ok, thank you, I understand "package main" is not necessary.
        I am surprised by your insistence in saying that "require" is an equivalent of an include. I suppose it is a question of word. What I call a "simple include", is like a macro, a textual equivalence, like macros or include processed by a C preprocessor : no syntax analysis is done. This is opposite to "require" which "load in external functions from a library at runtime" : I never said that I wanted to include fonctions nor make a library, I want a "simple include"...
        I would have accepted the answer that what I want to do is not possible, that it is not in the spirit of perl, coming from you a so good famous "saint"...I wonder if there is not something else that I miss.

      The perl way to do this is to isolate the common code in a module that exports symbols into the user's namespace. Look into Exporter and its various clones for packages that will assist you in setting this up.

      90% of every Perl application is already written.
      dragonchild