Any of the following three lines of code would create a sub named new_sub in the package Test, no matter which file contained the code.
Ah, but only the one with a package statement will necessarily use Test as the package for finding unqualified global variables. One-arg bless, caller() in called routines, and SUPER:: also will be affected, as well as probably other things that I'm unable to think of ATM. For all but trivial routines, using a proper package statement is best.
The following demonstrates how Nopkg::Super is connected to it's containing package "Pkg", not to "Nopkg":
$ cat pkg.pl
use strict;
use warnings;
sub main::Duper {
print "in main::Duper, called from pkg", scalar caller, "\n";
}
@Pkg::ISA = "Super";
@Nopkg::ISA = "main";
sub Super::Duper {
print "in Super::Duper, called from pkg ", scalar caller, "\n";
}
{
package Pkg;
sub Nopkg::Duper {
our @ISA; print "isa: @ISA\n";
my $obj = bless {}; print "blessed a ", ref($obj), "\n";
$obj->SUPER::Duper;
}
}
Nopkg::Duper();
sthoenna@DHX98431 ~/pbed
$ perl pkg.pl
isa: Super
blessed a Pkg
in Super::Duper, called from pkg Pkg
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.