in reply to main package
What package does it belong to ?
If you declared it as a package variable, whichever package statement is in effect. In your code, that would be "main".
If you declared it as a lexical variable, it's not found in a package.
What is main package ?
The currently selected package when the interpreter starts.
If I declare $var in a program, does it automatically belong to main package ?
No, the package in effect.
if I use strict, is it required to use main before the $anything ($main::anything) ?
If you declared it as a package variable, no.
If you declared it as a lexical variable, yes. Otherwise, you'll be accessing the lexical variable.
How does $anything become a part of main package ?
I don't understand.
Or does main mean main body (and not subroutines) of program that we are dealing with ?
It's just a namespace into which variables and subs can be placed. It doesn't mean anything.
So does it mean that everything from "#!/usr/bin/perl" to the "print $var; " excluding subroutines is main ?
Absent an overriding package statement, all code (including subroutines) will be compiled into main. That means that package variables and subs will be placed in the main namespace by default.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: main package
by manishrathi (Beadle) on Oct 06, 2009 at 18:39 UTC | |
by ELISHEVA (Prior) on Oct 06, 2009 at 19:13 UTC | |
by ikegami (Patriarch) on Oct 06, 2009 at 19:55 UTC |