develooper Front page | perl.perl5.porters | Postings from August 2013

Re: [perl #119095] Empty regular expression does not match in somecases

Thread Previous | Thread Next
Aristotle Pagaltzis
August 4, 2013 21:36
Re: [perl #119095] Empty regular expression does not match in somecases
Message ID:
* demerphq <> [2013-08-01 13:10]:
> I should add that its a feature that has extremely limit utility.
> As far as I can tell it is only useful in a case like this:
> if (/pat1/ || /pat2/ || /pat3/) {
>    s//$something/; # change whatever we matched
> }
> Or similar constructs. It actually makes no sense that it applies to
> m//, to the extent it should exist at all it should apply only to
> s///.

It makes perfect where this shortcut came from – namely ed, the ancient
Unix text editor. (Think about it: the only way to interact with the
editor is a command line. You have just performed a search. In the next
command you want to specify the same search again. What is the natural
syntax to say that? Also: the user will want to search for nothing… how

From there it was inherited by sed, and that is how it ended up in Perl.

A lot of the syntax and idioms lore that we think of as “regexps”, at
least in a Unix-y tradition, is really the regexp vernacular of ed. The
entire grep utility is an extraction of an ed idiom as a stand-alone

And even when I say all this, I am almost certainly being ahistorical –
I do not know in detail the lineage and history of ed and all its next
of kin (ex/vi, grep, sed, patch etc) and would actually be surprised if
the story weren’t more intertwined and complex than my portrayal, even
WRT just this one aspect.

(I expect Aaron to come up behind me and embarrass me now. :-) )

* demerphq <> [2013-08-01 13:10]:
> IMO we should nuke it and replace it with a (*LASTMATCH) metapattern.

Yes, probably. It made great sense in a text editor and may still make
sense in high-whipuptitude, low-manipulexity code (Perl as a glorified
sed, basically), but that is very little of the Perl that gets written
nowadays. It is effectively a pure liability in high-manipulexity code
(any code that has the CPAN nature, essentially).

But boy would we need a long deprecation cycle for this one. (It pre-
dates Perl itself!)

Aristotle Pagaltzis // <>

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About