473,326 Members | 2,126 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

[perl-python] text pattern matching, and expressiveness

20050207 text pattern matching

# -*- coding: utf-8 -*-
# Python

# suppose you want to replace all strings of the form
# <img src="some.gif" width="30" height="20">
# to
# <img src="some.png" width="30" height="20">
# in your html files.

# you can use the "re" module.

import re

text = r'''<html>
blab blab
<P> look at this <img src="./some.gif" width="30" height="20"> pict
and this one <img class="float-right" src="../that.gif">, both are
beautiful, but also look: <img src ="my.gif">, and sequel
<img src=
"girl.gif"> yeah! </p>
'''

new = re.sub(r'''src\s*=\s*"([^"]+)\.gif"''', r'''src="\1.png"''',
text)

print new

# the first argument to re.sub is a regex pattern.
# the second argument is the replacement string,
# which can contain captured pattern (the \1)
# the third argument is the text to be checked.
# an optional 4th argument is number of replacement
# to make. If ommitted, it replace all occurances of matches.

# see
# http://python.org/doc/lib/module-re.html

--------------------
# similar code in perl is s///. For example,
$text = "123";
$text =~ s/2/9/;
print $text;

----------------------
In languages human or computer, there's a notion of expressiveness.

English for example, is very expressive in manifestation, witness all
the poetry and implications and allusions and connotations and
dictions. There are a myriad ways to say one thing, fuzzy and warm and
all. But when we look at what things it can say, its power of
expression with respect to meaning, or its efficiency or precision, we
find natural languages incapable.

These can be felt thru several means. A sure way is thru logic,
linguistics, and or what's called Philosophy of Languages. One can also
glean directly the incapacity and inadequacy of natural languages by
studying the artificial language lojban, where one realizes, not only
are natural languages incapable in precision and lacking in efficiency,
but simply a huge number of things are near impossible to express thru
them.

One thing commonly misunderstood in computing industry is the notion of
expressiveness. If a language has a vocabulary of (smile, laugh, grin,
giggle, chuckle, guffaw, cackle), then that language will not be as
expressive, as a language with just (severe, slight, laugh, cry). The
former is "expressive" in terms of fluff, where the latter is
expressive with respect to meaning.

Similarly, in computer languages, expressiveness is significant with
respect to semantics, not syntactical variation.

These two contrasting ideas can be easily seen thru Perl vs Python
languages, and as one specific example of their text pattern matching
abilities.

Perl is a language of syntactical variegations. Python on the other
hand, does not even allow changes in code's indentation, but its
efficiency and power in expression, with respect to semantics (i.e.
algorithms), showcases Perl's poverty in specification.

Xah
xa*@xahlee.org
http://xahlee.org/PageTwo_dir/more.html

Jul 18 '05 #1
4 1872
Xah Lee wrote:
Perl is a language of syntactical variegations. Python on the other
hand, does not even allow changes in code's indentation, but its
efficiency and power in expression, with respect to semantics (i.e.
algorithms), showcases Perl's poverty in specification.


Clarify :-D.

--
John Small Perl scripts: http://johnbokma.com/perl/
Perl programmer available: http://castleamber.com/
Happy Customers: http://castleamber.com/testimonials.html

Jul 18 '05 #2
"John Bokma" <po********@castleamber.com> wrote in message
news:Xn*************************@130.133.1.4...
Xah Lee wrote:
Perl is a language of syntactical variegations. Python on the other
hand, does not even allow changes in code's indentation, but its
efficiency and power in expression, with respect to semantics (i.e.
algorithms), showcases Perl's poverty in specification.


Clarify :-D.


Clarification:

He (XL) is a troll and admits it. If only he would include that information
up-front in his (IMO worthless) [perl-python] posts, it would save a lot of
effort.

Daniel Fackrell

Jul 18 '05 #3
> He (XL) is a troll and admits it. If only he would include that
information up-front in his (IMO worthless) [perl-python] posts, it would
save a lot of effort.


He does - all of his posts start with [perl-python]. Now the big question is
which community comes up with a better/nicer/shorter/whatever filter -
pythonistas or perljunkies.

--
Regards,

Diez B. Roggisch
Jul 18 '05 #4
John Bokma wrote:
Xah Lee wrote:
Perl is a language of syntactical variegations. Python on the other
hand, does not even allow changes in code's indentation, but its
efficiency and power in expression, with respect to semantics (i.e.
algorithms), showcases Perl's poverty in specification.

Clarify :-D.


Well, I think it's pretty clearly troll-bait. Semantics != algorithms
and Perl (just like Python) has no such poverty WRT specification.

Sounds like someone who learned Python and forgot that it wasn't a
religion. Too bad, but a disease unique to no particular language. Perl,
Python, Ruby, C, APL, LISP... they've all had their unpleasant zealots.
Jul 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: David F. Skoll | last post by:
Hi, I'm tearing my hair out on this one. I'm trying to embed a Perl interpreter into a C program. I need to be able to create and destroy the interpreter periodically, but will never actually...
1
by: Julia Bell | last post by:
I would like to run the same script on two different platforms. The directory in which the script(s) will be stored is common to the two platforms. (I see the same directory contents regardless...
1
by: sm00thcrimnl13 | last post by:
if i have windows 2000 and know how to write perl scripts, how to i actuvate the script through perl?
1
by: smsabu2002 | last post by:
Hi, I am facing the build problem while installing the DBD-MySql perl module (ver 2.9008) using both GCC and CC compilers in HP-UX machine. For the Build using GCC, the compiler error is...
0
by: Kirt Loki Dankmyer | last post by:
So, I download the latest "stable" tar for perl (5.8.7) and try to compile it on the Solaris 8 (SPARC) box that I administrate. I try all sorts of different switches, but I can't get it to compile....
6
by: surfivor | last post by:
I may be involved in a data migration project involving databases and creating XML feeds. Our site is PHP based, so I imagine the team might suggest PHP, but I had a look at the PHP documentation...
4
by: billb | last post by:
I installed a perl extension for PHP to use some perl inside my php primarily because I have perl working with oracle and not php and oracle. So I want to use my old perl scripts, and use the...
223
by: Pilcrow | last post by:
Given that UNIX, including networking, is almost entirely coded in C, how come so many things are almost impossible in ordinary C? Examples: Network and internet access, access to UNIX...
4
by: vijayarl | last post by:
Hi All, i have the following software installed in my system : 1.OS: Win2k 2.Eclipse Version used :3.4.0 & even the perl too... 1. I have imported the my own perl project in Eclipse, when i...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.