Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re^3: How to import "global" variables into sub-scripts from main script?

by dsheroh (Monsignor)
on Mar 23, 2021 at 08:31 UTC ( [id://11130186]=note: print w/replies, xml ) Need Help??


in reply to Re^2: How to import "global" variables into sub-scripts from main script?
in thread How to import "global" variables into sub-scripts from main script?

Honestly, it smacks of overkill to me to have to declare variables repeatedly
One of the major functions of strict is to protect against typos in variable names. How can it detect a misspelled variable name if it doesn't know (via a declaration) what the correct name is?

Your answer seems to be "it should know because I declared it in the master script", but what if I write a different master script which uses your auxiliary script without declaring that variable? Because you split things up into multiple scripts and incorporate them into the master using require, each one needs to be able to stand alone, and that includes making its own variable declarations, as well as setting its own pragmas (strict, warnings, etc.).

if "strict" had actually said anything useful to me after I had gotten past the globals issue, i.e. if it had told me something about my code that had earlier escaped my notice
Perl tries, but it can't read your mind. Judging by the additional diagnostic messages for the "not imported" errors, it seems that what Perl thinks went wrong is that you imported some_sub() from another module, then mistakenly referred to it as $some_sub. That's not what you were actually doing, of course, but, since it's what Perl thought you were doing, that's the problem it tried to help you solve.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (6)
As of 2024-04-18 22:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found