From 7427c871abee6768cdd1c12d0ddf23f13cb37197 Mon Sep 17 00:00:00 2001 From: "David A. Madore" Date: Mon, 15 Feb 2010 23:47:16 +0100 Subject: Various stylistic improvements suggested by Max (such as using the // op). --- emergencyd.pl | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'emergencyd.pl') diff --git a/emergencyd.pl b/emergencyd.pl index 5766484..200881b 100755 --- a/emergencyd.pl +++ b/emergencyd.pl @@ -90,13 +90,12 @@ my $proto = getprotobyname("udp") or die "Can't resolve udp protocol: $!"; my $port; if ( defined($opts{p}) ) { $port = $opts{p}; - $port =~ /^(\d+)$/ or die "Invalid port number (-p option) $port"; + $port =~ /^\d+$/ or die "Invalid port number (-p option) $port"; } else { $port = DEFAULT_PORT; } -my $socket; -socket $socket, PF_INET6, SOCK_DGRAM, $proto or die "Can't create socket: $!"; +socket my $socket, PF_INET6, SOCK_DGRAM, $proto or die "Can't create socket: $!"; if ( defined(IPV6_V6ONLY) ) { setsockopt $socket, IPPROTO_IPV6, IPV6_V6ONLY, 0 or die "Can't set IPV6_V6ONLY option to 0: $!"; } @@ -114,7 +113,7 @@ if ( $opts{f} ) { } sub curtime { - my $fiddle = shift; $fiddle = 0 unless defined($fiddle); + my $fiddle = shift // 0; my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = gmtime(time+$fiddle); return sprintf("%04d-%02d-%02dT%02d:%02d:%02dZ",$year+1900,$mon+1,$mday,$hour,$min,$sec); } @@ -126,9 +125,9 @@ while (1) { my $buf; my $sender = recv($socket, $buf, 16384, 0); my @lines = split /\015*\012|\|/s, $buf; - my $command = $lines[0]; $command = "" unless defined($command); - my $timestamp = $lines[1]; $timestamp = "" unless defined($timestamp); - my $maccheck = $lines[2]; $maccheck = "" unless defined($maccheck); + my $command = $lines[0] // ""; + my $timestamp = $lines[1] // ""; + my $maccheck = $lines[2] // ""; next PACKET if $command eq ""; if ( $command eq "PING" ) { send $socket, "PONG\n", 0, $sender; @@ -157,8 +156,7 @@ while (1) { if ( $command eq "NOOP" ) { send $socket, "NOOP\n", 0, $sender; } elsif ( $command eq "DPID" ) { - my $pid = POSIX::getpid; - send $socket, "DPID\n$pid\n", 0, $sender; + send $socket, "DPID\n$$\n", 0, $sender; } elsif ( $command eq "DIE!" ) { send $socket, "BYE!\n", 0, $sender; exit 0; -- cgit v1.2.3