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

Re: feedback on successful module loading

by ggg (Scribe)
on Oct 07, 2004 at 18:58 UTC ( [id://397404]=note: print w/replies, xml ) Need Help??


in reply to feedback on successful module loading

Well, this is what I've settled on. Works great. Now I can upload variations of this to the several ISPs I'm involved with and be able to tell which modules they have available.
Many thanks to you all!
#!/opt/bin/perl -w print "running $0 in Perl $]\n"; my $result = eval "use CGI; 1"; if ($result) { print "CGI loaded\n"; } else { print "CGI failed\n"; } print "$@\n"; my $result = eval "use HTML::Template; 1"; if ($result) { print "Tmplt loaded\n"; } else { print "Tmplt failed\n"; } print "$@\n";
ggg

Replies are listed 'Best First'.
•Re^2: feedback on successful module loading
by merlyn (Sage) on Oct 07, 2004 at 21:22 UTC
    You should wrap all that in a BEGIN block if you want the imports from those "use" to act in a traditional fashion. Otherwise, you've essentially turned a use into a require, sorta.

    -- Randal L. Schwartz, Perl hacker
    Be sure to read my standard disclaimer if this is a reply.

Re^2: feedback on successful module loading
by diotalevi (Canon) on Oct 07, 2004 at 22:34 UTC

    You can make your code shorter by writing your code only once and putting your modules to test into a list.

    #!/opt/bin/perl -w print "running $0 in Perl $]\n"; for ( qw( CGI HTML::Template ) ) { print eval "require $_" ? "$_ ok\n" : "$_ failed: $@\n" }
      I was going to work on putting the module names into a DATA file and building the working script with another script. The result would have been just as long, but I wouldn't have written it by hand. I like your idea better. It has class!
      ggg

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://397404]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (3)
As of 2024-04-19 20:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found