3

I have a really strange problem but only when running Ubuntu ( on CentOS evertyhing is working ). I've made a script in Perl and used the Mail::IMAPClient module.

When I run the following command:

pp -o myapp perlscript.pl

Everything is working, but when I'm trying to execute the binary script (myapp), it gives me the following error:

Cannot connect through IMAPClient: No such file or directory at script/perlscript.pl line 22.

But when I'm running the perlscript.pl everything is OK ......
Do you have any idea why?

script:

#!/usr/bin/perl

use strict;
use Mail::IMAPClient;
use Data::Dumper;
use MIME::QuotedPrint ();

$|=1;

# Vars
my $odate = `date +'%d/%m/%Y'`; chomp($odate);
   $odate = '15/01/2012';
my $timeout = 120;

# Connect to IMAP server
my $imap = Mail::IMAPClient->new(
  Server   => 'imap.gmail.com',
  User     => 'my@email.com',
  Password => 'my_password',
  Port     => 993,
  Ssl      =>  1,
  )
  or die "Cannot connect through IMAPClient: $!";
David W.
  • 105,218
  • 39
  • 216
  • 337
Ricky Levi
  • 7,298
  • 1
  • 57
  • 65
  • You neglect to provide the necessary information so that we may [reproduce the problem](http://www.chiark.greenend.org.uk/~sgtatham/bugs.html#showmehow). Pasting your program would be a good start, so one can see what the error message on line 22 is about, until then, only speculation is possible. – daxim Jan 24 '12 at 15:17
  • Edited the page .... Line 22 is "my $imap = Mail::IMAPClient->new(" – Ricky Levi Jan 24 '12 at 16:41

1 Answers1

4

You are doing the error checking wrong way. You must inspect $@, not $!, for the constructor. Running the modified program (not yet compiled with pp) gives the useful error message:

Cannot connect through IMAPClient: Unable to connect to imap.gmail.com: Unable to load 'IO::Socket::SSL': Can't locate IO/Socket/SSL.pm in @INC (@INC contains: …) at (eval 7) line 2.

It seems like you forgot to tell the compiler to add the hidden dependency which it could not detect on its own.

daxim
  • 39,270
  • 4
  • 65
  • 132
  • I agree with daxim. The error message is from your `die` statement which simply means that a reference to a `Mail::IMAPClient` wasn't created. If you look at the documentation for Mail::IMAPClient under the [Errors](http://search.cpan.org/dist/Mail-IMAPClient/lib/Mail/IMAPClient.pod#Errors) section, you'll see that you need to examine `$@` since the object isn't created (which would have allowed you to use the [LastError](http://search.cpan.org/dist/Mail-IMAPClient/lib/Mail/IMAPClient.pod#LastError) method). – David W. Jan 24 '12 at 18:43
  • To expand on daxim's answer, use the following command to compile your app: `pp -z 9 -M IO::Socket::SSL -o myapp perlscript.pl`. `-z 9` is for reducing binary size. – Stamm Jan 24 '12 at 23:24
  • Actually the code example was copied from Google somewhere and I never looked at $!, I've added "use IO::Socket::SSL" and compiled it again ... now works. simple. Thank you very much for your help !! – Ricky Levi Jan 25 '12 at 08:31