3 ms·
> if you wanted to do simple text processing work there was always awk/sed and other little unix utilities in form of a command line program using pipes. But an
by bsg75 14y ago
> if you wanted to do simple text processing work there was always awk/sed and other little unix utilities in form of a command line program using pipes. But any thing more than that and you really had to write program
In the current landscape of scripting languages, what makes Perl superior to Python for text processing?
Asking as I have not touched Perl in over 10 years, after it was supplanted by Python for my needs. I use awk for many of the tasks I could call "text processing", and Python for more complex stuff.
- kamaal 14y ago>>I use awk for many of the tasks I could call "text processing", and Python for more complex stuff. I use Perl for both. That was the whole point of my post. Perl was invented because you shouldn't have the need to use (awk/sed etc) + (some other language) for text processing and what you call as 'complex stuff'.
- js2 14y agoWhat I found happening (as someone who started with Perl 4, then Perl 5, then largely moved to Python) is that my scripts often went through this evolution: shell (+ sed, + awk, ...), then Perl, then Python. That is, as the program grew more complicated, the best tool for the job (in its entirety) often shifted. The Perl to Python transition was usually due to Python including something in the standard library that Perl didn't. e.g. the example usage of pawk outputs json, which Python includes in the standard library. Doing that in Perl would mean installing a CPAN module. Anyway, at some point I started going from shell to Python and skipping the Perl step. These days I mostly reserve Perl for one liners and 90% of the time that's perl -[pn] -i -e '...'.
- bsg75 14y agoI have a pattern of the opposite. At one point almost everything was in Python, even very simple things. I "discovered" awk, and found I could do a lot of things in a few piped commands. Python is still my go-to for a tasks > 1 line of code, but it is still surprising what can be accomplished in just one line of bash.
- js2 14y agoTo be clear, I still write a ton of stuff in shell. I try to think ahead to whether what I want to do can be accomplished in shell + standard unix utilities more easily than in Python. I use Python if it's not easily possible in shell + unix utilities, or the script is likely to be more than a few hundred lines. Here's one I probably should've written in Python - https://gist.github.com/jaysoffian/f39fa2da8e7f340550f9 https://gist.github.com/jaysoffian/f39fa2da8e7f340550f9
- jmmcd 14y agoThen use Python for both. Everyone's happy. Python's nice syntax also makes pawk nicer to read than awk or perl, to my eyes.