At 01:17 PM 7/3/02 -0700, drieux wrote: >volks, > >I am trying to help with understanding >'what is basic/beginner' level - so I >have tried to put together a step by step >walk through from the simple concept to >the code in execution - close to what would >solve the Problem Description. > >So for those of you with 'editorial skills' >and the time, please review and kvetch with >me about > > http://www.wetware.com/drieux/pbl/perlTrick/CBO/PingIt/ > >as a way to look at evolving code upward from the >simple idea....
There's a portability problem with calling `ping $host`. On some platforms this will result in an indefinite ping. Others do not say "is alive" but instead give statistics. This is why Net::Ping was invented, but the problem it has is that it cannot send ICMP pings, only TCP pings, since you need to be root to ICMP ping and the ping program is setuid for this purpose. But generally TCP ping is good enough. You say in #2 # now we could solve our problem with stderr # the simple way with say # my $answer=`ping $host 2>&1`; # # but let's go for the bigger picture - and then use a piped open from which you read just the first line, then close the pipe; but that could result in a SIGPIPE. I do not see the 'bigger picture' you speak of; seems better to me to say (`ping $host 2>&1`)[0] to get the first line. And if you're going to encapsulate this in a subroutine, that subroutine ought to hide the ping output format and just return true/false, or something in between instead of making the caller check for the string 'is alive' or whatever their ping is going to say. In #3 you check for possibilities like the host not existing; IMHO this is better done before and independently of ping, with something like if (gethostbyname($host)...) Incidentally, many people object to the StudlyCaps form of naming, certainly for subroutines and variable names. They seem not to mind them in module names. In #4 you say # What about a little polymorphism to allow some level of recursion. # sub PingHost [...] I don't get it. I see neither polymorphism nor recursion in that subroutine. I don't think I could call this ready for Prime Time. It's at variance with the kind of 'best practices' code examples I'm used to seeing in the better CPAN modules and the better books. I'd suggest perusing Lincoln Stein's "Network Programming with Perl" for a bit and see whether or not you come to the same conclusion. -- Peter Scott Pacific Systems Design Technologies http://www.perldebugged.com/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]