
demerphq at gmail
May 16, 2008, 2:54 PM
Post #4 of 4
(101 views)
Permalink
|
2008/5/16 Abigail <abigail[at]abigail.be>: > On Fri, May 16, 2008 at 11:15:08PM +0200, demerphq wrote: >> 2008/5/16 Bram <p5p[at]perl.wizbit.be>: ... >> > Should the docs be clearer about the empty pattern and the copying of the /o >> > modifier? (which can be really confusing...) >> > >> > >> > Also, >> > >> > Add: use re 'eval' to the code: .... >> > >> > >> > So how exactly does use re 'eval' influences the regex? >> >> eeek. no idea. >> >> Both of these features are hard to deal with. It would be nice to >> banish them. But i dont think we can. Unfortunately. > > > We can't banish them in the sense of making them a syntax error. No, i was thinking of making /o a true no-op. And making the empty pattern only apply when the pattern is truly empty. IOW, a pattern containing a var which was the empty string should NOT trigger the empty pattern behaviour. > But we can change the documentation and remove any suggestion that > /o is a good idea. In the more than dozen years I've been answering > Perl questions, I've encountered people using /o many times. > > I cannot recall seeing a single useful use of /o. At best, the use > of /o is harmless. In perl 5.10 /o can be modestly faster than not using it. But i agree, almost every time it is used it results in pain and suffering for all concerned. > As for //, I hardly ever see it being used on purpose - and of the > cases I see it being used on purpose, most of them are (contrived) > examples of where // could be useful. I do see cases where people > use /$re/, and $re turns out to be empty. Slight disagreement here. Ive used the empty pattern a few times, sometimes out of laziness, and sometimes because it happens to make things nicer. The two examples im thinking of are : if (m/$some_big_nasty_pattern/ and $1 eq $something) { s///; } and the other is if (m/$pat1/ or m/$pat2/ or m/$pat3/) { s///; } The important thing to note is that the only time that ive ever used either is when doing a match and then needing to repeat the match as part of a s///. The first example is fairly unimportant. Using qr// you just reuse the pattern. The second is the only good reason for keeping this behaviour around, but IMO it would be just as use(ful|less) if it was restricted to a true empty pattern (as in lexically empty, not containing a var which may represent the empty string). > > I wonder whether it's useful (assuming it's feasible) to warn in cases > > /$var/ > > is used, and $var equals "". I think we should drop the behaviour for m// and make it warn. The empty string behavior should only kick in for s///. For /o we can just no-op it. (Once we fix the reasons why its actually useful in 5.10 -- sigh). Cheers, Yves -- perl -Mre=debug -e "/just|another|perl|hacker/"
|