in reply to Using variables within packages

I don't want to sound like a grumpy monk, but I'm not exactly sure what you're doing wrong. Do you have any code to provide us? We can start by looking at that.(and if it's a lot of code, don't forget the readmore tag)

--Coplan

Replies are listed 'Best First'.
Re: Re: Using variables within packages
by floyd (Acolyte) on May 07, 2003 at 17:05 UTC
    OK

    Firstly, I have used the AUTOLOAD code form Perl Black Book

    package Autoload; BEGIN { use Exporter(); @ISA = qw(Exporter); @EXPORT = qw(AUTOLOAD); } sub AUTOLOAD() { my $subroutine = $AUTOLOAD; $subroutine =~ s/.*:://; $callme = 'Genesis::'.$subroutine; &{$callme}; } END {} return 1;

    Then I'm using a package that I have called Genesis to read a datafile...

    package Genesis; BEGIN { use Exporter(); @ISA = qw(Exporter); @EXPORT = qw(&readdatafile); } ################## sub readdatafile { ################## open(FILE, "$datadir/data.dat" ); @thedata = <FILE>; close(FILE); } END {} return 1;

    variables.pl actually reads a data file for the different values, but for example, assume this simply reads...

    $datadir = "path/to/datafiles"; return 1;

    Finally, script.cgi 'requires' variables.pl, 'uses' Autoload and then executes 'readdatafile();'

    That is roughly that, so hopefully it will give you the idea of what I'm trying to do?

    Floyd