Comment

Comment by extortionist

My job is split between maintaining a giant legacy perl codebase and doing new dev work in python. I vastly prefer python overall, but perl's still the best when you need quick one-off scripts to tear through log files or do some quick regex subs on a bunch of files.

I don't think python has an equivalent of 'perl -p -i.bak -e 's/foo/bar/g' *', for example (which will do in-place regex substitutions on whichever files are passed in, additionally copying the original files to 'original.ext.bak').

The regex syntax is also bit more streamlined in perl, so I find it quicker and easier to throw together a script that's just doing regex stuff in it. A simple example:

>> $string =~ m/(pattern)/i;

>> my $match_text = $1 || '';

>> $string =~ s/pattern//gi;

>> import re

>> match_obj = re.find(r'(pattern)', string, flags=re.I)

>> match_text = ''

>> if match_obj is not None:

>> match_text = match.group(1)

>> string = re.sub(r'pattern', '', string, flags=re.I)

Of course, the same magic that makes perl great for those one-off kinds of scripts makes it less than ideal for complex or long-living scripts that need to be maintained by multiple people, in my opinion.

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton