Hello

It looks like response returns undef when it can not getline. I am assume the reason is that your POP3 server is disconnecting you once you enter a bad password. Not quite sure how to get around the warning other than patch Net::POP3 to handle that more gracefully. You can always disable warnings / diagnostics if the warning really bothers you. It's not always worthwhile to jump through hoops to avoid warnings.

Also, here are a few things I noticed when I looked at your code.

According to the documentation for Net::POP3, pass returns the number of messages in the mailbox. Since it returns a scalar you don't need to assign it to an array. You can do something like so:

my $count = $pop->pass($pass);

Also, if there are 0 messages in the mailbox pass will return 0E0 which will evaluate to true. Because of this you can bypass your check for defined as if it returned undef then you would've already caught it with your or do {....

print "Messages: $count\n";

Overall everything looks good! Keep up the good work!

Regards
Brad

In reply to Re: How to check number of messages using Net::POP3? by duct_tape
in thread How to check number of messages using Net::POP3? by BjoernD

Title:
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, 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:
    & &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.