Ramprasad A Padmanabhan wrote:

> 
> 
> How do I find in a function if a particular module is already loaded
> 
> for eg,
> 
> sub mysub {
> my @vars = @_;
> require Data::Dumper unless ( already_required('Data::Dumper'));
> print Data::Dumper::Dumper(\@vars);
> }
> 
> I want help writing the function already_required()

if you use the compile time 'use Data::Dumper' then you don't have to worry 
abut this since Perl will complain and won't compile if the module is 
missing. if you try to do it in run time, here is one way:

sub already_required{

        my $module = shift;

        eval{
                require $module;
        };

        if($@){
                #-- something is wrong. $module could be missing
                return 0;
        }else{
                #-- looks like $module is successfully loaded!
                return 1;
        }
}

david

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to