Preferences

johnisgood parent
Oh but there is an objective way to substantiate this claim. How familiar are you with Perl? It will not work (to convince you) if you do not know the language, you need to be quite familiar with it. There are extremely short ways to do string manipulation, for one, think 3 characters short. So, assuming you know Perl, it is definitely easier AND faster, than say, Python.

Trivial example:

Replace all numbers in a string (faster and easier in Perl):

Perl:

  $string =~ s/\d+/NUM/g;
Python:

  import re
  string = re.sub(r'\d+', 'NUM', string)
Perl's design history is text processing as a first-class goal. It has syntax-level efficiency, and expressive power (e.g. s///e, tr///, inline regex flags, etc.). Do you want me to go on? These are all objective ways to substantiate the claims I made.

Perl is implemented in C with a runtime that aggressively optimizes text processing. The core primitives such as split, join, substr, index, s///, etc. are tight wrappers around C functions with minimal object overhead. In Python, even simple string manipulations go through Python's object system, and in Python strings are immutable, so every manipulation creates a new string object, which incurs extra memory allocation and garbage collection.

Perl is typically 30-80% faster in similar regex-heavy workloads because there is no import overhead, there is internal opcode dispatch for regex, and no allocation of new strings until match is confirmed.

Additionally, Perl frequently wins by eliminating boilerplate, as shown above. It has advanced features with simple syntax, too, meaning you get fewer lines of code, fewer concepts to juggle, and faster iteration time. Python, by contrast, forces the developer to switch between the re module for non-trivial regex, multiple string method calls, and so forth.

Shall I go on? I can objectively substantiate my claims with regarding to Perl vs. Python, as I have done above, but if it is not enough for you, I could easily go on. I can give you benchmarks, too, if you so wish. FWIW, my claim was: you can achieve string manipulation / text processing faster (both execution speed and development time) and easier in Perl vs. Python.

---

The bottom line is, that for text-heavy workloads, Perl remains the more efficient and developer-friendly tool as opposed to Python; a conclusion that can be quantified, measured and defended objectively. It is not an opinion, nor a matter of taste.

Just to reiterate, across a wide range of text processing tasks, Perl consistently offers:

- Fewer lines of code

- More powerful and concise idioms

- Better CLI support

- Faster execution for regex-heavy operations

- Less boilerplate and setup overhead

This list is non-exhaustive, and I can get more into the implementation details (I did touch it above), too, if you so wish, such as, for example, how Perl's interpreter is string-first and how Perl uses SVs that are internally optimized to handle both numbers and strings interchangeably without conversion overhead, as opposed to Python that uses PyObject-based immutable strings which incur copy-on-write penalties and method dispatch overhead.


johnisgood OP
FYI:

  [johnisgood@arch regex]$ hyperfine 'perl regex_test.pl' 'python3 regex_test.py'
  Benchmark 1: perl regex_test.pl
    Time (mean ± σ):      1.807 s ±  0.028 s    [User: 1.752 s, System: 0.054 s]
    Range (min … max):    1.780 s …  1.857 s    10 runs

  Benchmark 2: python3 regex_test.py
    Time (mean ± σ):      3.316 s ±  0.230 s    [User: 3.246 s, System: 0.069 s]
    Range (min … max):    3.052 s …  3.858 s    10 runs

  Summary
    perl regex_test.pl ran
      1.84 ± 0.13 times faster than python3 regex_test.py
This is for a very simple script!

You know why?

Because Perl was practically designed for text processing and regex.

It has:

- A regex engine that's deeply integrated and highly optimized.

- Less overhead (no interpreter startup, minimal memory structures).

- Simpler string substitution and less abstraction.

Seriously, it is not a matter of opinion.

I hope you are convinced now.

In case you are not, let me know, I will let you in on a lot of great details. :)

johnisgood OP
Using the down-vote button is such an absurd way to disagree. So whoever you may be, you should engage in a conversation. With what do you disagree, and why?

This item has no comments currently.