Admin-Stress wrote: > Hi, > > In this example, to 'catch' if the socket could not be > created, by using -> or die "...."; > > #!/usr/bin/perl -w > use IO::Socket; > $remote = IO::Socket::INET->new( > Proto => "tcp", > PeerAddr => "localhost", > PeerPort => "daytime(13)", > ) > or die "cannot connect to daytime port at localhost"; > > How can I use 'if' statement? > So I can handle the exception better. > > $remote = IO::Socket::INET->new( > Proto => "tcp", > PeerAddr => "localhost", > PeerPort => "daytime(13)", > ); > > if (...) { > cleanup(); > print "socket error"; > exit(0); > }
IO::Socket::INET->new returns undef on error (and sets $@ with an error message), althout this isn't terribly well documented. So you can say: if (!$sock) { ... or unless ($sock) { ... -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]