Perl module: Difference between revisions

Content deleted Content added
Procedural example: Actually let the user run the thing. Missing the most critical part, the include path!
Format code
Line 199:
sub new {
my($class, %args) = @_;
my $self = bless({}, $class);
my $target = exists $args{target} ? $args{target} : "world";
$self->{target} = $target;
return $self;
}
Line 220:
sub target {
my $self = shift;
if( @_ ) {
my $target = shift;
$self->{target} = $target;
}
 
return $self->{target};
Line 253:
sub print {
my $self = shift;
print $self->to_string(), "\n";
}
Line 296:
$mainVar = 'b';
{
# NOTE previously created packages and package variables still accessible
package Sp1;
our $sp1bVar = 'bb';
print "$main::mainVar\t$sp1aVar\t$sp1bVar\n"; # note mainVar needs qualifying
{
{
package Sp2;
our $sp2bVar = 'bbb';
print "$main::mainVar\t$Sp1::sp1aVar$Sp1::sp1bVar\t$sp2aVar$sp2bVar\n";
} # note mainVar and sp1...Var need qualifying
print "$main::mainVar\t$sp1bVar$sp1aVar\t$Sp2::sp2bVar$Sp2::sp2aVar\n";
} # note package Sp1 applies by default
# main applies again by default; all package variables still accessible as long as qualified
Line 325:
<source lang="perl">
sub CGI::bi { # define target namespace (CGI) and sub name (bi)
return b(i($_[0]));
}
</source>