Sure. What caught my attention was this:
sub mail {
local $self = shift;
local $dbh = $self->param('dbh');
my $q = $self->query();
local $session = $q->param('session');
....
}
Since you've got a variable called $self, I'm assuming this is an object method. What you're doing here is creating a local version of the package variable $self. So if you had a package global called $self (which you probably shouldn't) you'd be overriding it. That is generally not the behavior that you want in a method. (or any sub, really.) You want a lexical variable called $self, one which is unrelated to any other $self in any other lexical block. The reason I assumed you did not know the difference is because I saw in that code lots of locals mixed in with mys in places that did not make a lot of sense. I would write that code as:
sub mail {
my $self = shift;
my $dbh = $self->param('dbh');
my $q = $self->query();
my $session = $q->param('session');
}
Here's an excellent document explaining when to use each: Coping With Scoping. |