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

I have to import the functions and variables which is in EXPORT and EXPORT_OK variable.

@EXPORT = qw(&shuffle @card_deck); @EXPORT_OK = qw(&collect @list); our @card_deck = qw(this is for testing); our @list = qw( ass Jack queen king ); sub shuffle { return "shuffle is done\n" } sub distribute{ return "distribute is OK\n" } sub collect{ return "Collection is finished\n" } 1;

if we use the use package it will import the Export variable if we use the use package qw(..) it will import the Export_OK variable I have to import both the variable in one (use) statement.

for example the export is having more then 100 function and export_ok is having couple of function and some variable. How to import both the function and variable.

Replies are listed 'Best First'.
Re: Export in perl
by moritz (Cardinal) on Feb 07, 2011 at 12:41 UTC
Re: Export in perl
by Anonymous Monk on Feb 07, 2011 at 11:38 UTC
Re: Export in perl
by Khen1950fx (Canon) on Feb 07, 2011 at 14:58 UTC
    To import both variables in one use statement, do this:
    use YourModule qw(:DEFAULT collect @list);
    :DEFAULT covers all of @EXPORT. For @EXPORT_OK, each element that you want must be called individually: hence, distribute won't be exported. I would do your script like this:
    package YourModule; use strict; use warnings; use Exporter; BEGIN { $Exporter::Verbose = 1; } our (@ISA, @EXPORT, @EXPORT_OK); BEGIN { require Exporter; @ISA = qw(Exporter); @EXPORT = qw(shuffle @card_deck); @EXPORT_OK = qw(collect @list); } use YourModule qw(:DEFAULT collect @list); our @list = qw(ace jack queen king); sub shuffle { return "shuffle is done\n"; } sub distribute { return "distribute is OK\n"; } sub collect { return "collect is finished\n"; }

      Didn't know about the :DEFAULT tag, thanks. On that subject, a lot of modules provide an :all tag.

      our @EXPORT = qw(shuffle @card_deck); our @EXPORT_OK = ( @EXPORT, qw( collect @list ) ); our %EXPORT_TAGS = ( ':all' => \@EXPORT_OK );
      use YourModule qw( :all );
      Too much typing where regex will do
      use YourModule '/./';