Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Any help greatly appreciated: I am trying to run a script that checks multiple POP3 accounts at once. The script times out, and the error message from the log is "Can't call method "login" without a package or object reference at line 31."

--I'm on a Unix server, running Perl Version 5.006001

--The script can be found here: The instructions (such as they are) can be found here:

--I do not get the error immediately; it takes about 30 or 40 seconds for the "connection error" text to appear.

--When I run the script, everything appears to work fine: by calling I get an html document to log in to, I am then taken to a window with three frames, I can set up new accounts, and all data is written to the "db" files. I can even send mail (/usr/lib/sendmail). Here is the '' script:

#!/usr/bin/perl use CGI qw(:standard); use myPOP3; if(param('tb')) {printToolbar();exit;} checkLogin(); $account = param("a") || err(); $p_act = param("act") || ""; $p1 = '?'; $pwd = param("pwd") || $p1; readPref('./db'); if(($PREF[2] eq $p1)) { if($pwd eq $p1) { askPwd(); exit; } else { $PREF[2] = $pwd; } } print "Content-type: text/html\n\n"; print "<html>\n"; printScript2(); print "<body topmargin=0 leftmargin=0 marginheight=0 marginwidth=0><fo +nt face=\"times\" size=2>\n<form method=\"post\">\n"; deleteMsg($p_act) if ($p_act =~ /^del\|/); $pop = myPOP3->new($PREF[0]) || print "Connection error.\n"; $count = $pop->login($PREF[1], $PREF[2]); $scr = '<img src="img/scr.gif" width="8" height="16" border="0">'; if(!$count) {print "Login incorrect.\n";} else{ $count = $count * 1; print "&nbsp;Messages: $count\n"; if($count>0){ $tmp = $pop->list(); %sizes = %$tmp; print "<table cellspacing=1>\n"; print "<tr bgcolor=\"\#e0e0e0\"><td>&nbsp;</td><td>$scr</td><t +d><font size=2><b>Subject</b></font></td><td width=40><font size=2><b +>Size</b></font></td><td><font size=2><b>From</b></font></td><td><fon +t size=2><b>Date</b></font></td></tr>\n"; for($i=1;$i<=$count;$i++){ $m = $pop->top($i); %HEAD = undef; &parseHeader($m); local($subj) = $HEAD{'Subject'}; if(length($subj)>50){ $subj = substr($subj,0,40) . '...'; } local($mdate) = formatDate($HEAD{'Date'}); $_ = $HEAD{'From'}; local($mfrom) = $_; $mfrom = $1 if /(.*)</; $_ = $HEAD{'Content-Type'} || ''; local($matt) = '&nbsp;'; $matt = $scr if /multipart/i; print "<tr>\n"; print "<td><input type=\"checkbox\" name=\"selMsg$i\" valu +e=\"$i\" onfocus=\"blur()\"></td>\n"; print "<td><font size=2>$matt</font></td>\n"; print "<td nowrap><font size=2><a href=\"$acc +ount&m=$i\" target=\"message\" onfocus=\"blur()\" onclick=\"return rc +v($i)\">$subj</a></font></td>\n"; print "<td align=right><font size=2>" . $sizes{$i} . "</fo +nt></td>\n"; print "<td nowrap><font size=2>" . encodeHTML($mfrom) . "< +/font></td>\n"; print "<td nowrap><font size=2>$mdate</font></td>\n"; print "</tr>\n"; } print "</table>\n"; } } $pop->quit; print "<input name=\"act\" value=\"\" type=\"hidden\"><input name=\"fa +dr\" value=\"\" type=\"hidden\">"; print "<input name=\"a\" value=\"$account\" type=\"hidden\"><input typ +e=\"hidden\" name=\"pwd\">"; print "</form>"; print '<form name="frmR" method="post"><input name="m_from" type="hidd +en"><input name="m_to" type="hidden"><input name="m_subj" type="hidde +n"><input name="doc" type="hidden"></form>'; print "<form name=\"frmRcv\" method=\"post\" action=\"\" tar +get=\"message\"><input type=\"hidden\" name=\"a\" value=\"$account\"> +<input type=\"hidden\" name=\"m\"><input type=\"hidden\" name=\"pwd\" +></form>"; print "\n</font></body>\n</html>\n"; exit; #---------------------------------------------------- sub printToolbar(){ print "Content-type: text/html\n\n"; print "<html>\n"; printScript(); print<<TOOL; <body topmargin=0 leftmargin=0 marginheight=0 marginwidth=0> <table border=0 background="img/bg.gif" width="100%"> <tr> <td ><a href="#" onclick="sendMsg();return false;" onfocus="blur() +"><img src="img/m_new.gif" border="0" alt="Send message"></a ><a href="#" onclick="replMsg();return false;" onfocus="blur() +"><img src="img/m_rep.gif" border="0" alt="Reply message"></a ><a href="#" onclick="fwdMsg();return false;" onfocus="blur()" +><img src="img/m_rep.gif" border="0" alt="Forward message"></a ><a href="#" onclick="delMsg();return false;" onfocus="blur()" +><img src="img/m_del.gif" border="0" alt="Delete message"></a ></td> </tr> </table> </body> </html> TOOL } sub printScript(){ print<<__END; <head> <script language="JavaScript"> function delMsg(){ var f=parent.frames.inbox; if(!f||!f.delMsg) return; f.delMsg(); } function sendMsg(){""); } function replMsg(){ var f=parent.frames.inbox; if(!f||!f.replMsg) return; f.replMsg(); } function fwdMsg(){ var f=parent.frames.inbox; if(!f||!f.fwdMsg) return; f.fwdMsg(); } </script> </head> __END } sub printScript2(){ print<<__END; <head> <script language="JavaScript"> function rcv(i){ var f = document.forms.frmRcv; f.m.value = i; f.pwd.value = top.frames.account.pwds[$account-1]; f.submit(); return false; } function delMsg(){ var f = document.forms[0]; if(!f) return; f.pwd.value = top.frames.account.pwds[$account-1]; var ch=false; var ch0=false; var chn=""; for(i=0;i<f.elements.length;i++){ var b=f.elements[i]; if(b.type!="checkbox") continue; ch0=true; ch = ch || b.checked; if(b.checked) chn=chn+"|"+b.value; } if(!ch){ alert(ch0?"Select a message.":"No messages."); return; } if(confirm("Permanently delete selected messages from server?")){ f.act.value="del"+chn; = ""; f.action = ""; f.submit(); } } function replMsg(){ var f = document.forms.frmR; if(!f) return; var f0=top.frames.message; if(!f0.doc) {alert("No message to reply.\\nRead a message first.") +;return;} f.action="";"wnd_repl"; f.m_from.value=f0.m_from; f.m_to.value=f0.m_to; f.m_subj.value=f0.m_subj; f.doc.value=f0.doc; f.submit(); } function fwdMsg(){ var f = document.forms[0]; if(!f) return; f.pwd.value = top.frames.account.pwds[$account-1]; var ch=false; var ch0=false; var chn=""; for(i=0;i<f.elements.length;i++){ var b=f.elements[i]; if(b.type!="checkbox") continue; ch0=true; ch = ch || b.checked; if(b.checked) chn=chn+"|"+b.value; } if(!ch){ alert(ch0?"Select a message.":"No messages."); return; } var fadr = prompt("Enter email address to forward:",""); if(fadr != "") { f.act.value = chn; f.fadr.value = fadr; = "message"; f.action = ""; f.submit(); } } </script> </head> __END } sub deleteMsg(){ return if !@_; local($pop, $count, @s); $pop = myPOP3->new($PREF[0]); $count = $pop->login($PREF[1], $PREF[2]); if($count){ @s = split(/\|/, $_[0]); foreach (@s){ $pop->delete($1) if /^(\d+)$/; } } $pop->quit; } sub parseHeader(){ local($a)=$_[0]; local($prev)=undef; foreach (@$a){ if ( /^([a-zA-Z-]+)\:\s*(.*)/ ) {$HEAD{$1} = $2; $prev=$1;} elsif($prev){ if (/^\s*(.+)/) {$HEAD{$prev} .= "\n$1";} else {$prev=undef;} } } } sub formatDate(){ return "" if !$_[0]; $_[0] =~ s/^(\D*)//; $_[0] = substr($_[0], 0, rindex($_[0], ':')); return $_[0]; } sub encodeHTML(){ $_[0] ||= ""; $_[0] =~ s/</&lt;/g; $_[0] =~ s/>/&gt;/g; return $_[0]; } sub checkLogin(){ $_ = $ENV{'HTTP_COOKIE'}; $user = $1 if /user=(\w+)/; err('Access denied.') if !$user; } sub readPref(){ err() if !@_; open(PAGE, "$_[0]/$user.dbx") || err('Error open DB.'); local(@db) = <PAGE>; close(PAGE); local($i)=1; foreach (@db){ if ($i eq $account) {@PREF=split(/\|/, $_);last;} $i++; } err() if !@PREF; } sub err(){ $_[0] ||= " "; print "Content-type: text/html\n\n"; print "&nbsp;$_[0]"; exit; } sub askPwd(){ print<<__END2; Content-type: text/html <html> <body> <form method="post" onsubmit="top.frames.account.pwds[$account-1]=docu +ment.forms[0].pwd.value; return true;"> <input type="hidden" name="a" value="$account"> Password: <input type="password" name="pwd"> <input type="submit" value="Login"> </form> </body> </html> __END2 }

In reply to can't call method without package or object reference by bwv871

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • 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, 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, 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others browsing the Monastery: (5)
    As of 2017-04-26 17:55 GMT
    Find Nodes?
      Voting Booth?
      I'm a fool:

      Results (487 votes). Check out past polls.