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.
my $a = 'Perl';
my $b = $a;
$b =~ s/pe/ea/i;
Why not do something to $a and obtain $b, just like js does with Array.map. Why the need to copy $a into to $b and then replace? Much more ellegant in Ruby: a = 'Ruby'
b = a.gsub(/ru/i, 'mo') my $a = 'Perl';
my $b =~ s/pe/ea/ir; % perl -MData::Dumper=Dumper -e 'my $a = 'Perl'; my $b =~ s/pe/ea/ir; print Dumper $b;'
$VAR1 = undef;
You probably mean: my $a = 'Perl';
my $b = $a =~ s/pe/ea/ir;
Anyway, thank you for the /r modifier, it didn't know what it did, since there's no example in perlre(1).
Am I missing anything?
I liked Perl back in the day and used it a lot but even my old sweet-jesus-what-was-I-thinking Python code is a LOT more readable than my cleanest old Perl code.
I'd be curious to hear from folks who've also been deep in Python and Perl but stuck with Perl rather than Python— different use cases? Coding styles?