develooper Front page | perl.beginners | Postings from January 2002

Re:What's wrong with this?

From:
Jonathan E. Paton
Date:
January 28, 2002 11:07
Subject:
Re:What's wrong with this?
Message ID:
20020128190727.97896.qmail@web14608.mail.yahoo.com
> use IO::Socket;
> $port=21;
> 
> $sock = IO::Socket::INET->new(PeerAddr  =>'localhost',
>                                         PeerPort =>
> $port,
>                                         Proto => 'tcp') ;
> die &inetdconf unless ($sock);
> 
> 
> my $cmd4=" net stop inetd && net start inetd";
> system($cmd4);
> 
> sub inetdconf()
> {
> 	my $cmd=" c:\\oxe\\cygwin\\bin\\sed.exe 's/^\#ftp/ftp/' 
> c:\\cygwin\\usr\\local\\etc\\inetd.conf >
> c:\\cygwin\\usr\\local\\etc\\inetd.new 
> ";# Comment out ftp entry in /etc/inetd.conf
> 	system($cmd);
> 	my $cmd2=" c:\\oxe\\cygwin\\bin\\mv.exe 
> c:\\cygwin\\usr\\local\\etc\\inetd.new
> c:\\cygwin\\usr\\local\\etc\\inetd.conf"; 
> # Move new file into place
> 	system($cmd2);
> }
> 
> But it always returns 0.Why?

Because of:

die &inetdconf unless ($sock);

which dies if you don't get a socket.  For the text to
return it looks at the LAST VALUE evaluated (I don't mean
by eval()) in inetdconf() - in this case system().  This
strangly returns false on sucess (value "0"), hence
provided you fail to get a socket, you get the value "0"
printed.

Jonathan Paton

__________________________________________________
Do You Yahoo!?
Everything you'll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About