http://www.perlmonks.org?node_id=949145

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

I recently wrote this text which I think is not bad writing. but the script fails for no reason. I do not understand the reason for the error

#!/usr/bin/perl -w use strict; ##use Email::Simple; use Net::POP3; use Net::POP3::SSLWrapper; pop3s { my$server = 'pop.wanadoo.fr'; ##la tu dois mettre ton identifiant de connexion my $login = 'serge******'; ##la tu dois mettre tonmot de passe my$passwd = '*****'; $| = 1; print "connecting to $server..\n"; my $pop = new Net::POP3 $server or die "error: can't connect to $server: $!\n"; print "ok\n"; $pop->login($login,$passwd); $pop->ok or die "error: wrong username or password\n"; my($undelete,$size) = $pop->popstat; my$last = $pop ->last; print "mail box size: $size\n", "$undelete unread mail(s).\n", "last read mail was number $last\n\n"; my$fetched = 0; for my $num (1..$undelete) { my$msg = $pop->get($num); next unless ref $msg; $fetched += $pop->list($num); printf "\rfetched %2.0f%%",$fetched *100/$size; $pop->delete($num); } print $/; $pop->quit; }

Can you help me master the perl "Fu" to find a solution to my problem

Replies are listed 'Best First'.
Re: how to use Net::POP3::SSLWrapper
by planetscape (Chancellor) on Jan 21, 2012 at 10:49 UTC

    "Fails", how? What is the error?

    Do you need a sub before pop3s? Some spaces between my and $SomeVariableName (several instances)?

    HTH,

    planetscape

      the script fail during the prime parcourt of the loop I made ​​some minor changes to the code

      print "connecting to $server..\n"; my $pop = Net::POP3->new($server, Port => 995) or die "error: can't connect to $server: $!\n"; print "ok\n";

      this is my error to stderr

      localhost ~]$ perl deletemailpop3s.pl connecting to pop.wanadoo.fr.. ok Use of uninitialized value in concatenation (.) or string at deletemai +lpop3s.pl line 28. mail box size: 12914033 313 unread mail(s). last read mail was number Use of uninitialized value in numeric eq (==) at /usr/lib/perl5/5.8.8/ +Net/POP3.pm line 311. Use of uninitialized value in numeric eq (==) at /usr/lib/perl5/5.8.8/ +Net/POP3.pm line 311. ...etc...

        Examining the first waarning message and the following output indicates that $last is undef which implies that my $last = $pop->last; failed. The following warnings pertaining to badness inside POP3.pm is pretty much consistent with $pop already being in a bad state.

        What did the code look before you changed it?

        True laziness is hard work
Re: how to use Net::POP3::SSLWrapper
by Khen1950fx (Canon) on Jan 22, 2012 at 00:35 UTC
    Mail::POP3Client worked better for me.
    #!/usr/bin/perl -l use strict; use warnings; use Mail::POP3Client; my $host = 'pop.example.com'; my $user = 'user'; my $password = 'password'; my $pop = Mail::POP3Client->new( HOST => $host, USESSL => 1, USER => $user, PASSWORD => $password, ); print "You have ", $pop->Count, "messages";