in reply to different results from the same sub

Your module doesn't even compile. How could it have given that output?

Below, I

use strict; package mship; use IO::Socket::INET; use Socket; use Carp; ############## sub connection ############## { my ( $ip, $tcp_port ) = @_; my $ipadd = Socket::inet_aton($IP) or croak "$IP is not valid\n"; my $port_name = getservbyport($TCP_PORT, 'tcp') or "unknown"; my $remote_name = gethostbyaddr( $ipadd, 2 ) or croak "Unable to resolve hostname for $IP\n"; my %stats = ( 'ip' => $ip, 'port' => $tcp_port, 'port_name' => $port_name, 'remote_name' => $remote_name, 'status' => accepts_conn($IP, $TCP_PORT) ? "Up" : "Down" ); print "sub connection port = $TCP_PORT IP = $IP\n"; return %stats; } ############# sub accepts_conn ############# { my ( $ip, $tcp_port ) = @_; my $sock = IO::Socket::INET ->new( Timeout => 5, PeerAddr => $ip, PeerPort => $tcp_port, Proto => 'tcp', ); return $sock ? 1 : 0; } 1;
#!/usr/bin/perl -w use strict; use mship; my %stats = mship::connection('xxx.19.208.27', '9101'); while (my ($key, $value) = each(%stats)) { print "$key = $value\n"; } print "\n"; my $status = mship::accepts_conn('xxx.19.208.27', '9101') ? "Up" : "Do +wn"; print("Status: $status\n");