Is Perl *that* good? (was: How's ruby compare to it older brother python)

Leif B. Kristensen junkmail at solumslekt.org
Mon Apr 26 14:28:13 EDT 2004


Cameron Laird rose and spake:

> Long ago, I was myself involved in a tiny way with
> parish records for Finnmark and Troms.  I wish I'd
> been able to do more ...

That's very interesting from my point of view. Starting this autumn, by
the way, the Norwegian National Archive will begin to publish scanned
images of parish records on the Web. They plan to finish this job in a
couple of years, and then go on to other popular sources for
genealogists, such as probates, court records, and land transactions.

> I'm glad things are working for you.  I'm all for
> not-duplicating effort.  Do you realize you can use
> PHP from the command line?  As I understand your
> explanation, it doesn't reflect AT ALL on a defici-
> ency in PHP string-handling; to my eye, PHP can do
> the operation just about as well as Perl.

It probably could, but at the time I wrote my FoxPro extraction script I
was very much into Perl. I was very happy to find the XBase module, and
besides, I have been unable to find something similar in any other
language that I have more than a nodding aquaintance with.

> I continue to conclude that all these languages are
> roughtly equally competent at managing strings.

Perhaps, but right now I think that I'm in love with Python. Consider
these two equivalent routines in PHP and Python:

PHP:
function get_place($x) {
    $query = "select pl1, pl2, pl3, pl4, pl5 
              from places where place_id = $x";
    $handle = mysql_query($query);
    $row = mysql_fetch_row($handle);
    $pl_string = '';
    if ($p_num == 1) return '';
    $i = 0;
    for ($j = 0; $j<5; $j++) {
        if ($row[$j] != '' && substr($row[$j], 0, 1) != '-') {
            $pl[$i] = $row[$j];
            $i++;
        }
    }
    for ($j = 0; $j < ($i-1); $j++)
        $pl_string .= $pl[$j].', ';
    $pl_string .= $pl[$i-1];
    return ltrim(rtrim($pl_string));
}

Python:
def get_place(x):
    c=db.cursor()
    c.execute("select pl1, pl2, pl3, pl4, pl5 
                from place where place_id = %d" % (x))
    result=c.fetchone()
    return ', '.join([p for p in result if p and p[0] != '-'])

Consider that my entire Web site is written in PHP. I stumbled across
Python just a few weeks ago, and got substantial help with the latter
version of the routine from Paul Rubin on this list.

My PHP coding may be suboptimal, but in terms both of codability and
readability as well as in sheer elegance, I find the Python version
superior in any way.

regards,
-- 
Leif Biberg Kristensen
http://solumslekt.org/
Validare necesse est



More information about the Python-list mailing list