Jeff Pang wrote:
Hello,lists,

Seeing these code below please.I can't know why the var defined in the main 
script can been accessed in the modules that used by the main script?thanks.

From `perldoc vars`:

While the vars pragma cannot duplicate the effect of package lexicals (total transparency outside of the package), it can act as an acceptable substitute by pre-declaring global symbols, ensuring their availability to the later-loaded routines.

This means any variable declared by vars can be accessed outside of the file it is declared in.

The second part of the understanding comes from Exporter. When it exports a thingy, it uses a typeglob to make the thingy in the package the same as in the 'use'ing module. In other words, for your My::HTML module, it does this:

  $main::q = \*My::HTML::q;


For more details, see:

  perldoc vars
  perldoc -f our
  perldoc perlfunc (and search for 'our')

  perldoc Exporter
  perldoc perlop (and search for 'typeglob')
  perldoc perlsub (and search for 'typeglob')


--

Just my 0.00000002 million dollars worth,
   --- Shawn

"Probability is now one. Any problems that are left are your own."
   SS Heart of Gold, _The Hitchhiker's Guide to the Galaxy_

* Perl tutorials at http://perlmonks.org/?node=Tutorials
* A searchable perldoc is available at http://perldoc.perl.org/

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to