> -----Original Message-----
> From: Janek Schleicher [mailto:[EMAIL PROTECTED]] 
> Sent: Monday, September 30, 2002 10:05 AM
> To: [EMAIL PROTECTED]
> Subject: Re: Finding if a module is already 'require'd
> 
> 
> Ramprasad A Padmanabhan wrote at Mon, 30 Sep 2002 09:36:50 +0200:
> 
> > 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()
> 
> You don't need it.
> From perldoc -f require:
> 
>                Otherwise, demands that a library file be included
>                if it hasn't already been included.  The file is
>                included via the do-FILE mechanism, which is
>                essentially just a variety of "eval".  Has
>                semantics similar to the following subroutine:
> 
> So a required module is only loaded when it hadn't been loaded yet.

As from which version of Perl this functionality has been included.
I'm asking this because, I have seen in the DBI code (DBI.pm file)
That the author is checking if a DBD::* module has been already installed (loaded) ...

Here an extract of DBI.pm file :


sub install_driver {            # croaks on failure
    my $class = shift;
    my($driver, $attr) = @_;
    my $drh;

    $driver ||= $ENV{DBI_DRIVER} || '';

    # allow driver to be specified as a 'dbi:driver:' string
    $driver = $1 if $driver =~ s/^DBI:(.*?)://i;

    Carp::croak("usage: $class->install_driver(\$driver [, \%attr])")
                unless ($driver and @_<=3);

    # already installed
    return $drh if $drh = $DBI::installed_drh{$driver};

[snip]


José.


**** DISCLAIMER ****

"This e-mail and any attachment thereto may contain information which is confidential 
and/or protected by intellectual property rights and are intended for the sole use of 
the recipient(s) named above. 
Any use of the information contained herein (including, but not limited to, total or 
partial reproduction, communication or distribution in any form) by other persons than 
the designated recipient(s) is prohibited. 
If you have received this e-mail in error, please notify the sender either by 
telephone or by e-mail and delete the material from any computer".

Thank you for your cooperation.

For further information about Proximus mobile phone services please see our website at 
http://www.proximus.be or refer to any Proximus agent.


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

Reply via email to