sobering observation, python vs. perl

Marko Rauhamaa marko at pacujo.net
Thu Mar 17 15:11:51 EDT 2016


BartC <bc at freeuk.com>:

> On 17/03/2016 18:53, Marko Rauhamaa wrote:
>> BartC <bc at freeuk.com>:
>
>>> sub replacewith{
>>>     $s = $_[0];
>>>     $t = $_[1];
>>>     $u = $_[2];
>>>     $s =~ s/$t/$u/;
>>>     return $s;
>>> }
>>>
>>> Although once done, the original task now looks a proper language:
>>>
>>> print (replacewith("I have a dream","have","had"));
>>
>> Now try your function with:
>>
>>     print (replacewith("I have a dream",".","had"));
>
> Yeah, it needs your quotemeta line (whatever that does). But the call
> is unaffected as the clutter is in the function.

Well, you fell in the trap. Most perl programmers would fall in it. Same
with bash programmers, including myself.

That's why I'm wondering if Python could come to the rescue and offer a
solid alternative to bash. You have to go out of your way to get into
accidental quoting/escaping problems in Python.


Marko



More information about the Python-list mailing list