On 2/24/2011 12:42 AM, Uri Guttman wrote:
"TM" == Ted Mittelstaedt<t...@mittelstaedt.us>  writes:



   TM>  $sockaddr       = 'x C n a4 x8';
   TM>  Th first two bytes are length (0) and family, both of which are
   TM>  unsigned char, so 'x C' (or 'n') handles those.

   TM>  use Socket;

   TM>  $that = sockaddr_in($port,inet_aton($newshost));

   TM>  ($newshost is the FQDN of the new host, $thataddr is the IP# of the
   TM>  news host)

   TM>  but as I said before, I don't want to rewrite everything.

jeez.

use IO::Socket ;

my $sock = IO::Socket->new( "$host:$port" ) ;

done.

use a module for at least that. dealing with pack templates for socket
addresses is insane and never needed anymore.


Uri, I am perfectly aware of what constitutes modern programming
practice.  And the fact of the matter is that your very wrong, because
if I was going to rewrite this code the correct way would be to use one of the NNTP Perl modules (NNTP Client for example) The listgroups
script could probably be replaced by something along the lines of

use News::NNTPClient;

$nntp = new News::NNTPClient("xxx.xxx.xxx","",2);

outer loop
get a listgroup list
iterate through it

inner loop
get an article list from the current group
iterate through it and write the stuff out
end inner loop

end outer loop


But I will point out that perl modules are built in a pyramid, you
have ones like NNTPClient that use IO::Socket and that module
uses Socket and that module uses...what?  Well, it turns out it
uses the same approach that's in the listgroups.pl script.

If your answer to a bug in the program is to hack out the
section and replace it with a module, your basically saying
that you don't know how the section works.  So your going to
drop in a black box that does the same as that section.  In
other words, you don't know how the black box works anymore
than you know how the section your hacking out works.

And the day that a new platform comes along and the module your
using blows up on that then you will be just as screwed as
I was.  Worse, probably, because I didn't give up I kept plugging
away at it.  You won't, you will just complain loudly for the
maintainer of the IO::Socket module to fix it and do nothing until he does.

I'm not proposing that someone take and write a brand new project
from scratch.

For new perl code you want to use as many of the WIDELY USED
modules that have ONGOING SUPPORT as you can.  That is a given.

But for older, running code that breaks on new platforms, wouldn't
you rather just correct the bug in it than spend all that time
rewriting it?

Ted

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to