apessos has asked for the wisdom of the Perl Monks concerning the following question:

I have recently installed the Everything Engine on my system and am running into problems that the user password is never being sent out.

My question isn't about what is happening here, but rather, with my attempt to debug and track down the error. While I would like to know what is going with the mailer, I think it is better to understand why my debugging efforts are screeching to a halt.

The code in question is here:

... 36: use Everything::MAIL; 37: my $addr = node2mail($$haverow{email},$n); 38: $n = getNodeById(getId($n), 'force'); 39: $str.="<BR><H3>Your password and username should be on its way;< +/H3>"; 40: $str.= "Addr7: " . $addr; ...
Wihch displays the following output:

Your password and username should be on its way

Addr7: Mail::Sender=HASH(0x8dadfc0)

I thought I understood perl, but I am always humbled when I run across another facet that I don't understand. Why is Mail::Sender=HASH being displayed instead of "1...". I feel as if this should be easy for me to understand, but i've been debugging all day and my brain is frazzled. The code for node2mail is below. The purpose of doing this was to return address, username, etc. from node2mail and display it on the site to help me identify if the wrong values are being passed and further track down the error.
sub node2mail { my ($addr, $node) = @_; my @addresses = (ref $addr eq "ARRAY") ? @$addr:($addr); my $user = getNode($$node{author_user}); my $subject = $$node{title}; my $body = $$node{doctext}; use Mail::Sender; my $SETTING = getNode('mail settings', 'setting'); my ($mailserver, $from); if ($SETTING) { my $MAILSTUFF = $SETTING->getVars(); $mailserver = $$MAILSTUFF{mailServer}; $from = $$MAILSTUFF{systemMailFrom}; } else { $mailserver = "localhost"; $from = "root\@localhost"; } my $sender = new Mail::Sender{smtp => $mailserver, from => $fr +om}; $sender->MailMsg({to=>$addr, subject=>$subject, msg => $body}); $sender->Close(); my $value = "1..."; return $value; }

Replies are listed 'Best First'.
Re: HASH question
by sauoq (Abbot) on Nov 11, 2002 at 20:13 UTC

    Going strictly on the information you've given, the problem you are seeing makes little sense. I suspect there is more to it. If you are running under mod_perl and making changes to the code but not making sure the server reloads that code, you may not be testing what you think you are...

    Can you give us more information?

    -sauoq
    "My two cents aren't worth a dime.";
    
      I hope this is helpful. This is the "email me my password" code:
      [% my $str; $str.="Forgot your username or password? All we need is one of the f +ollowing blanks filled in correctly and you should be able to find th +e answers to your most perplexing question"; $str.=$query->start_form("POST", $ENV{SCRIPT_NAME}); $str.='<INPUT TYPE="hidden" NAME="op" VALUE="lostpasswd">'; $str.=$query->hidden('node_id',getId($NODE)); $str.="Your username:"; $str.='<INPUT TYPE="text" NAME="username" VALUE=""><br>'; $str.="Your e-mail address:"; $str.='<INPUT TYPE="text" NAME="email" VALUE=""><br>'; $str.=$query->submit("sexisgood", "Mail me my password, Cowboy!"); $str.=$query->end_form; if($query->param('op') eq 'lostpasswd' and ($query->param('username' +) || $query->param('email'))){ my $haverow=0; my $username=$query->param('username'); my $email=$query->param('email'); my @N; if($username){ @N = getNode($username, getType('user')); $haverow=$N[0]; } if(!$haverow and $email){ @N=$DB->getNodeWhere ({email => $email}, $DB->getType('user' +)); $haverow=$N[0]; } if($haverow){ my ($n) = getNode('Password Mail', getType('mail')); $$n{doctext} =~ s/\<name\>/$$haverow{realname}/; $$n{doctext} =~ s/\<user\>/$$haverow{title}/; $$n{doctext} =~ s/\<passwd\>/$$haverow{passwd}/; $$n{doctext} =~ s/\<site_name\>/$HTMLVARS{site_name}/; $$n{doctext} =~ s/\<site_url\>/$HTMLVARS{site_url}/; use Everything::MAIL; my $addr = node2mail($$haverow{email},$n); $n = getNodeById(getId($n), 'force'); $str.="<BR><H3>Your password and username should be on its wa +y</H3>"; $str.= "Addr7: " . $addr; print "<BR>$addr"; } else{ $str="<B>Couldn't find any info that matched what you gave us +, make sure you typed in everything correctly!</B><BR><BR>".$str; } } $str; %]

      To see what is going on, gohere.

      Enter apessos as the username and any email address. The code is very similar to what I have already posted. The node2mail is a package stored at /usr/local/lib/perl5/site_perl/5.6.1/Everything.

      If there is any other piece of information that would be helpful, let me know.

      You know, something that you said didn't sit right with me. The part about the server not reloading the code. So, I restarted Apache and I don't get that hash output anymore. I wonder if that means I have to restart Apache each time I make a change?
        No, just add
        PerlModule Apache::StatINC PerlInitHandler Apache::StatINC
        to your httpd.conf.

        Reading the Guide is essential when maintaining a mod_perl based system.

        rdfield

Re: HASH question
by pg (Canon) on Nov 11, 2002 at 22:21 UTC
    First, in Perl, when you print a HASH ref, what you get will be HASH(0xaddr). You can interprete this as the address where the content of the HASH resides. Secondly, in Perl, a class is actually stored as a HASH, so there is no surprise to see HASH(0xaddr) being a part of your print out, when you print the object. The first part, I mean the portion before the = sign, is the "name" of the class. Third, see this helps the programer a lot, you can determine the type of the object, by simply look at what stored in its ref. This is very powerful. It makes possible for you to have functions take generic objects, and then base on the type of the objects to determine how to deal with them. There are times that you want to process apple as apple, and orange as orange, but you may some times receive apple and some times orange.

      Object doesn't have to be a hash reference. It may be an array ref, a scalar ref, a glob ref ...

      Hashes are just most common.

      Jenda