Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Using the perl modules depends upon the availability of another module.

by jesuashok (Curate)
on Dec 08, 2005 at 06:52 UTC ( #515147=perlquestion: print w/ replies, xml ) Need Help??
jesuashok has asked for the wisdom of the Perl Monks concerning the following question:

Hi Perl lovers,

In perl code some time we used to give the statments like

my $result = $one || $two;

Every perl lovers what the above perl statement does.

Here my question begins.

use Module1 || Module2

use Module1 && Module2

Perl Module2 is going to do soem generic activities if Module1 is not installed in the System. this is what my objetive.

I am damn sure that there could be a valid reason why that is not acceptable in perl

I am eager to know the answers from all perl lovers !perl haters. :-)

"Keep pouring your ideas"

Comment on Using the perl modules depends upon the availability of another module.
Re: Using the perl modules depends upon the availability of another module.
by ikegami (Pope) on Dec 08, 2005 at 07:41 UTC

    It would be use Module1 || use Module2, but that doesn't work because use dies on failure. You might try to wrap the use in an eval BLOCK, but that doesn't work because of compile-time vs run-time issues. You could succeed, however, by following the advice given in "use" dynamic module. Alternativly, eval EXPR does the trick:

    # Approximate # use Module1 || use Module2; BEGIN { eval qq{ use Module1 }; eval qq{ use Module2 } if not $@; die("Unable to load Module1 or Module2\n" if not $@; }
      Alternatively, there is the if module
      use Module1; use if $INC{'Module1.pm'}, 'Module2';
      looks a little nicer, although I don't think I've ever actually used it.

      MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
      I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
      ** The third rule of perl club is a statement of fact: pod is sexy.

        It'll never get to the second line. If Module1 doesn't load, the first use will die.
Re: Using the perl modules depends upon the availability of another module.
by tye (Cardinal) on Dec 08, 2005 at 09:19 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://515147]
Approved by spiritway
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (8)
As of 2014-08-20 13:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (113 votes), past polls