Here is my go, I like this blog entry about arguments in functions: https://www.matheus.ro/2018/01/29/clean-code-avoid-many-arguments-functions/
#!/usr/bin/env perl use strict; use warnings; use Data::Dumper; use IO::Socket::INET; sub portCheck { my ($server,$port) = @_; my $sock = IO::Socket::INET->new( PeerAddr => $server, Timeout => 1, PeerPort => $port, Proto => 'tcp', ) || return 0; return 1; } my @checks = ( [ 'perlmonks.com',80 ], [ 'perlmonks.org',80 ], [ 'perlmonks.org',25], ); my @kids; for (@checks) { my $pid = fork // die; if ($pid) { push @kids,$pid; next; } exit portCheck(@$_); } for (0..$#kids) { print "@{$checks[$_]}\n"; waitpid($kids[$_],0); print $? >> 8 ,"\n"; }
In reply to Re: A question of fork efficiency
by trippledubs
in thread A question of fork efficiency
by synless
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |