punkish has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl -w BEGIN { open(STDERR, ">>foo.err") or die "invisible error"; warn localtime() . ": $0 started " . $/; } use strict; use Foo; start(); # start the program while (1) { process(); # the main program logic goto_sleep(); # goto sleep } ### and then, in Foo.pm ####### sub process { # create an IMAP connection eval { $imap = Mail::IMAPClient->new( Server => $IMAP, User => $UNAME, Password => $PWD, Uid => 0, Debug => $DEBUGGING, ) or carp "Cannot connect to $IMAP as $UNAME: $@"; }; open LOG, ">>foo.log"; print LOG ($@) ? "failed with $@\n" : "connected successfully\n"; close LOG; }
My logic is thusly -- if something is wrong enough for the script to not compile, it will write the reason in foo.err and die rightaway. However, if compilation is successful, then it will try to connect to the IMAP host. If that fails, it will write to foo.log and go to sleep for a specified time, and then wake up and try again.
Except, my logic is wrong. If the connection to the IMAP host fails, the error gets written to foo.err and the script dies. This indicates that the script is checking for the IMAP host connection right at compile time.
What am I doing wrong, and how can I achieve what I want?
What I want is -- after the script starts up successfully, I want it to make the connection to the IMAP host. If successful, do the rest of its stuff, else write a note in the log and go to sleep only to try again later.
Update: Stranger still... if the connection fails, I get an error in foo.err, and yet, I also get "connected successfully" in foo.log. This is most bewildering.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Understanding compiletime vs. runtime
by tilly (Archbishop) on Feb 04, 2005 at 06:53 UTC | |
by punkish (Priest) on Feb 04, 2005 at 12:56 UTC | |
by tilly (Archbishop) on Feb 05, 2005 at 08:42 UTC | |
by punkish (Priest) on Feb 05, 2005 at 22:21 UTC | |
by tilly (Archbishop) on Feb 06, 2005 at 07:37 UTC | |
|
Re: Understanding compiletime vs. runtime
by thor (Priest) on Feb 04, 2005 at 04:57 UTC |