What’s the use of in Perl?

The answers above are all correct, but it might come across more plainly if you understand general UNIX command line usage. It is very common to want a command to work on multiple files. E.g. ls -l *.c The command line shell (bash et al) turns this into: ls -l a.c b.c c.c … in … Read more

Javascript regex compared to Perl regex

From ECMAScript 2018 onwards, many of JavaScript’s regex deficiencies have been fixed. It now supports lookbehind assertions, even unbounded ones. Unicode property escapes have been added. There finally is a DOTALL (/s) flag. What is still missing: JavaScript doesn’t have a way to prevent backtracking by making matches final (using possessive quantifiers ++/*+/?+ or atomic … Read more

Perl: Use s/ (replace) and return new string [duplicate]

require 5.013002; # or better: use Syntax::Construct qw(/r); print “bla: “, $myvar =~ s/a/b/r, “\n”; See perl5132delta: The substitution operator now supports a /r option that copies the input variable, carries out the substitution on the copy and returns the result. The original remains unmodified. my $old = ‘cat’; my $new = $old =~ s/cat/dog/r; … Read more