Hi - > -----Original Message----- > From: Admin-Stress [mailto:[EMAIL PROTECTED]] > Sent: Thursday, January 16, 2003 5:49 AM > To: perl > Subject: Catching unknown socket (or unknown handle / filehandle) > > > 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); > } > > I dont know how to check if a handle has not ben created. Anyone > can explain to me? > > Thanks, > pot >
Two ways: 'do' statement - $remote = IO::Socket::INET->new( ... ) or do {..whatever..}; 'eval' (block) statement - eval { $remote = IO::Socket::INET->new( ... ); }; if (!@) {..failed..do whatever..} Aloha => Beau; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]