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

Hi All,

I have a main configuration script which is called from all my other perl files, the config script contains subroutines with $variables .. I use the tag include 'script.pl'; but whenever I run any of the scripts calling the config script I get all the -w errors "Name main::tag used only once"

Am I doing something wrong? The script functions ok, but the command line report those errors

Thanks

Replies are listed 'Best First'.
Re: Using External Subroutines
by data64 (Chaplain) on Nov 19, 2001 at 01:28 UTC
    Please post the configuration script and the script that does the "require".
Re: Using External Subroutines
by Anonymous Monk on Nov 19, 2001 at 01:36 UTC
    OK, Well...I wont post all of it because it is huge, but here is an example: config file
    sub check { $statement = 'SELECT * FROM users'; $dbh = DBI->connect("DBI:mysql:$DBNAME:localhost","user","pass"); $sth = $dbh->prepare($statement); $sth->execute(); while(my $ref = $sth->fetchrow_hashref()) { $address= $ref->{'add'}; $phone= $ref->{'phone'}; $password= $ref->{'pass'}; } }

    The main script then has the following sort of set-up:
    require "config.pl"; check(); print "$name";
    Thats not the actual files but it will give you an idea of what i am doing, the $name would produce a -w error saying used only once
      Your config.pl should be made into a module and $name needs to be exported from config so that it is available in the calling script.
      For more information see perlman:lib:Exporter, perlman:perlmodlib and perlman:perlmod.

      So you will need to add code like
      package ModuleName; require Exporter; @ISA = qw(Exporter); @EXPORT = qw(...); # symbols to export by default

      @EXPORT should contain the name of the variables and the subroutines you want to be able to access from calling scripts.
      Also, your calling script should do a use ModuleName; rather than require ModuleName;
        is that really the only way to do it? no way to make variables global or anything ?
Re: Using External Subroutines
by Anonymous Monk on Nov 19, 2001 at 00:56 UTC
    Sorry .. above I said I use the tag 'include script.pl' I use require "script.pl" ... :)