In scriptA.pl, there is use DBI
In scriptB.pl, there is require "scriptA.pl"
But we still cannot use DBI package in scriptB.pl
Any way to handle this except repeating use DBI in scriptB.pl?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The scoped nature of
useis a documented feature:You could do what you want by going back to the stone age as in the following example, but please don’t.
Using
MyModuleas a stand-in forDBI:and then calling
MyModule::foofromscriptA.pland from
scriptB.plall kicked off from a main program of
gives the following output:
You also could disable the scoping safety-feature with nasty
evalgames, but please don’t do that either.If your design needs improvement—maybe
scriptAandscriptBbelong in the same package—that would be a far better investment of your time. Otherwise, bite the bullet and expend nine keystrokes.Please note that executing Perl libraries at runtime via
doorrequireare a seriously dated approaches. The perlmod documentation describes the modern approach.