[ale] Py[h]hon syntax (sic)
Christopher Fowler
cfowler at outpostsentinel.com
Thu Jan 27 13:43:49 EST 2005
Could someone show me how to convert this code from perl to python.
This is a typical piece of code that I use:
sub ping($$) {
my ($IP, $tries) = @_;
my $resp = undef;
my $max = ($tries ? $tries : 2);
for(my $x = 0; $x < $max; $x++) {
open(OUT, "ping -c 1 $IP |");
while(<OUT>) {
next unless m/(\d+)\sreceived/;
$resp = $1;
_print(sprintf("Try: %d/%d Resp: %d\n", ($x+1), $max, $resp));
}
close(OUT);
if($resp) {
$x = $max;
} else {
}
}
return $resp;
}
All the function does is test to see if a host is up. IF not it then
reports and error to a user using Net::SMTP. Is there an equivalent in
Pyton? If not I could simply roll my own using sockets.
On Wed, 2005-01-26 at 12:12, Benjamin Scherrey wrote:
> uh... read it again six months after you wrote it and understand what
> the heck it does? :)
>
> Perl really does excel as a scripting language for processing files
> of text, especially using regular expressions. That's its original
> purpose and, sticking to that scope, I couldn't argue conclusively for
> another language over it. However, python and ruby, while perhaps
> introduced as scripting languages, are really full fledged and elegant
> high level application development languages that are purposely written
> to develop complex and powerful applications beyond scripts and admin
> tasks. Perl has a gazzillion majic symbols that one must remember to do
> anything complex with and there are more (correct!) ways to approach a
> given task than there are perl programmers so consistency of code
> amongst a group of programmers (even with the group size==1!) is almost
> never found. Even in respect to its regular expression abilities, the
> new version of python is as expressive and as efficient so, in the area
> where perl once stood above all others, it has not maintained its dominance.
>
> Without trying to engage in a language war I think the question you
> pose is not the right one. Given enough mastery of any given programming
> language I could make the same assertion of being capable of
> accomplishing almost any task. Does that mean all languages are equally
> functional or expressive? Certainly not. It really should be which
> language is the right tool for a particular job. Perl was designed for a
> particular job and does it well. Outside of that scope, however, perl
> shows its shortcomings pretty rapidly. Just because something *can* be
> done using a given language doesn't mean its a good idea.
>
> For me, C++ and python cover the full breath of any programming
> project I've ever encountered or conceived of. Yet, to this day, each
> time I approach a new programming task I always try to identify what
> languages are best suited for that task if only to identify what idioms
> or patterns might best be used to attack the problem at hand. Each
> language has its own particular idioms that drive its best use and can
> teach us things about problem solving even when we may not end up using
> that particular language in the final solution. That is why one should
> learn as many languages as one can - it makes you more expressive.
>
> -- Ben Scherrey
>
> Christopher Fowler wrote:
>
> >I'm finding that I can accomplish almost any task in Perl that I want.
> >Only problem is that it is not fully OOP. Other than OOP what can you
> >do in say Ruby or Python that you can not do in Perl?
> >
> >
> >
More information about the Ale
mailing list