I've looked around for a way to easily debug scoping problems.
I used
App::Trace,
and
Devel::SimpleTrace,
which I prefer to
diagnostics.
I didn't cleanup the code, but I followed
chromatic's advice about single-argument bless being almost always an error and fixed the bless; also, I declared $sound1 and $sound2 in your sound sub.
#!/usr/bin/perl -T
use strict;
use warnings;
use App::Options;
use App::Trace;
use Devel::SimpleTrace;
Animal::Hog->sound();
{
package Animal::Hog;
sub new {
&App::sub_entry if ($App::Trace);
my ($this, @args) = @_;
my $class = ref($this) || $this;
my $self = { @args };
bless $self, $class;
&App::sub_exit($self) if ($App::Trace);
return($self);
}
sub sound {
my $sound1 = 'knor1';
my $sound2 = 'knor2';
&App::sub_entry if ($App::Trace);
my $self = shift;
&App::sub_exit($_) if ($App::Trace);
print $sound1, "\n",
$sound2, "\n";
}
if ($App::debug && &App::in_debug_scope) {
print "Debug output\n";
}
}
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.