[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Whois as BBEdit Perl Filter?



 Chris Nandor <pudge@pobox.com> writes:


> At 13.24 -0400 2000.05.12, Jim Correia wrote:
>>I'm not even a perl guy :-)
>
>>    while( defined($line = <$sock>) )
>>    {
>>        $line =~ tr/\x0A/\x0D/;
>>        chomp $line;
>>        print $line, "\n";
>>    }
>
> Apparently, that first line up there isn't true.  :)

Uh huh.

I say we take a vote to make Jim an honorary "Perl Guy".  Just substitute
"whois.geektools.com" for "whois.internic.net", and you can find any domain
on the globe!

Now let's take Jim's code and give it the standard "Filter Make-over":

#!perl -wnl

sub BEGIN {
use IO::Socket;

$host = "whois.geektools.com";

$| = 1;
}

$sock = new IO::Socket::INET(PeerAddr => $host,
                             PeerPort => 43,
                             Proto => 'tcp');

die "IO::Socket::INET $!" unless $sock;

print $sock "$_";

print $sock "\x0A\x0D";

while( defined($line = <$sock>) )
    {
     $line =~ tr/\x0A/\x0D/;
     chomp $line;
     print $line;
    }

close($sock);

print "\n";
__END__

Didn't really trim much off. Jim's code was already fairly "low-fat". "-l"
only saves us one chomp(), and changes 'print "\n\n";' to 'print "\n";'.
I don't really know that having the explicit BEGIN block is any better
trade-off than the explicit while() it replaces.  I could place the "use"
outside the BEGIN block. It only gets executed once regardless.

So, not much room for improvement that I can see.

I need to issue a potential warning. A LONG list of domains could prove
dangerous.  It's not a good idea to abuse a whois server.  Use this
responsibly.

--B

--
Webmaster/MacPerl Guru
*****************************************************
Mycoinfo, the World's First Mycology e-Journal
http://www.mycoinfo.com/
*****************************************************


# ===== Want to unsubscribe from this list?
# ===== Send mail with body "unsubscribe" to macperl-request@macperl.org