> -----Original Message-----
> From: Chad Kellerman [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, August 27, 2002 1:46 PM
> To: [EMAIL PROTECTED]
> Subject: Re: eval on a $SIG{KILL}- newbie question
> 
> 
> Sorry everybody,
> 
>    I have been trying to work on this all day but nothing...
> 
> IF a perl module uses:
> connect($sock, sockaddr_in($rport, $raddr))
>         or die "Can't connect to $ssh->{host}, port $rport: $!";
> 
> How do I catch the die() in an eval statement;  I have been using:
> 
> eval {       
>                 alarm 10;
>                 $ssh->login($user);
>                 ($out, $error, $exit) = $ssh->cmd($cmd);
>                 alarm(0);
>         }; # end of eval statement        
>         if ($@ =~ /Can't/) {
>                try_again($ip, $host_name) = @_;
>         }        
> 
> but the eval still doesn't pass the program to the sub try_again.
> 
> Sorry for being such a newbie, but I have been trying to follow the
> oreilly book and still it just isn't happening.

That's how you do it. Here's a boiled-down example:

   eval { foo(); };
   if ($@ =~ /Can't/) {
      print "Caught it!: $@\n";
   }

   sub foo { die "Can't connect\n" }

If I run that, it prints:

   Caught it!: Can't connect

So, I would look for the following:

1. The code inside the eval is dying, but not with the Can't connect
message. Try printing $@ after the eval to see what it contains.

2. The code in the module is catching the die() somewhere else, and not
passing it back to you.

3. The die() in the module is never being called.

Also, what is this supposed to be doing? It looks very odd:

   try_again($ip, $host_name) = @_;

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to