Re: [SLUG] script to parse and compare an IP address

From: Paul M Foster (paulf@quillandmouse.com)
Date: Sat Apr 01 2006 - 12:56:18 EST


Sick Twist wrote:

> I am trying to write a script that parses an unknown IP address from a
> page of HTML, compares the IP address to a file and overwrites the file
> if the saved IP address is different. My question is, what language
> should I investigate to accomplish this? Is this able to be done with a
> bash script and command line utilities or is there another language like
> perl or python that would be better suited for this task? C has always
> been my game so I'm less familiar with the strengths and capabilities of
> some of the other tools out there. Thanks in advance!
>

Let the language wars begin! ;-}

If this is something that you could run from a web page, I'd suggest
PHP. Its syntax is the most similar to C, of the languages you mentioned.

I've written code in Perl, but I no longer do. Perl is hard to read, and
has odd conventions for naming variables, depending on the type of the
variable and the context. However, for doing regexp work, Perl has the
simplest interface. It's built in to the language; completely integrated.

Python is my choice for this kind of work. However, Python has some
quirks, too. First, it has almost no end-of-line delimiters and requires
strict indentation, a fact that causes jeers from its detractors. In
addition, to do regexp work you must include a statement at the
beginning of the file to pull in the regexp module; like an #include
directive in C. The method of doing regexp work is more complicated than
Perl. But the language is more... orthogonal?... than Perl. Perl's kinda
down-and-dirty it'll-figure-out-what-you-mean. Python is more rigorous.
Larry Wall (Perl creator) built Perl so that there many many ways to do
the same thing, some quite counter-intuitive. Guido Van Rossum (Python's
creator) wanted a language with the power of Perl, but with a more
regular/orthogonal/rigorous syntax. Fortunately, both these languages
don't require the same pre-declaration of variables that C does, and
they do garbage collection that C can't.

These scripting languages drive me crazy because their syntax for
certain common tasks is just different enough from each other and C that
you often make stupid mistakes while coding. (else if, elseif, elif,
elsif...) This is one of the reasons I prefer PHP when I can use it--
it's close enough to C syntax that I seldom use the wrong keyword, and I
still have to terminate lines with a semicolon (unlike Python).

If this is a one-shot deal, you might just consider using grep/sed and
bash. That's got to be easier than mastering the intricacies of a whole
new language.

Paul

-- 
Paul M. Foster
-----------------------------------------------------------------------
This list is provided as an unmoderated internet service by Networked
Knowledge Systems (NKS).  Views and opinions expressed in messages
posted are those of the author and do not necessarily reflect the
official policy or position of NKS or any of its employees.



This archive was generated by hypermail 2.1.3 : Fri Aug 01 2014 - 20:26:32 EDT