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

When i create my own perl module and execute,it fails to execute due to compilation errors at require Exporter.. This is my code in the module: package LineParse; use XML::Simple; use Data::Dumper; use strict; BEGIN { use vars qw(@EXPORT @EXPORT_OK @ISA); use Exporter; @ISA = qw(Exporter); @Export = qw(&readconfig ); @EXPORT_OK = qw(); } sub readconfig() { # my xml parsing code } When i execute a syntax check on this module, it says compilation Error.Please help me. sriram$perl -c LineParse.pm Global symbol "@Export" requires explicit package name at LineParse.pm line 14. BEGIN not safe after errors--compilation aborted at LineParse.pm line 18.

Replies are listed 'Best First'.
Re: perl module creation problem
by EvanCarroll (Chaplain) on Nov 13, 2009 at 03:16 UTC
    update I couldn't read that badly formated code, so I rewrote it and redid my reply, with proper formatting it become very aparent it was because your @Export had different case than the variable you declared to be global @EXPORT. Also, use our for declaring globals unless you have to work with very old perls.
    package LineParse; use XML::Simple; use Data::Dumper; use strict; use Exporter; our @ISA = qw(Exporter); our @EXPORT = qw(&readconfig ); our @EXPORT_OK = qw(); sub readconfig() { # my xml parsing code }


    Evan Carroll
    The most respected person in the whole perl community.
    www.evancarroll.com
Re: perl module creation problem
by Jenda (Abbot) on Nov 13, 2009 at 12:55 UTC

    Apart from what Evan already said ... drop the BEGIN{...} and require Exporter. Unless you are doing something very very awkward with the @ISA, @EXPORT and @EXPORT_OK in the rest of your code, the BEGIN{...} is unnecessary.

    Jenda
    Enoch was right!
    Enjoy the last years of Rome.

      It seems that @EXPORT = qw( foo ) works in addition to @EXPORT = qw( &foo ) for a function foo in the module. I didn't realize the "&" was required. Why does it still work without the "&"?

        Because most often you want to export subroutines and because most of the time whe you call subroutines you do not use the & either. So it's reasonable to write the module so that it exports the subroutine if you do not specify any sigil.

        Jenda
        Enoch was right!
        Enjoy the last years of Rome.