New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Empty regular expression does not match in some cases #13141
Comments
From @ppisarHello, this code: q{"} =~ m/"/; if (q{a} =~ m//) { should print TRUE, but it prints FALSE. In other words, empty regular expression does not match. There is some side I observe this behaviour with somewhat patched 5.16.3, vanilla 5.18.0 You can use this one-liner instead: $ perl -e 'q{"} =~ m/"/; if (q{a} =~ m//) { print qq{TRUE\n} }' -- Petr |
From @pjcjOn Wed, Jul 31, 2013 at 07:34:07AM -0700, Petr Pisar wrote:
I think this is one of those "it's a feature, not a bug" moments. From perlop: The empty pattern // -- |
The RT System itself - Status changed from 'new' to 'open' |
From @TuxOn Wed, 31 Jul 2013 07:34:07 -0700, Petr Pisar (via RT)
Mope. $ perldoc perlreref If 'pattern' is an empty string, the last successfully matched regex is
-- |
@Tux - Status changed from 'open' to 'resolved' |
From zefram@fysh.orgPaul Johnson wrote:
Addendum, which should probably go in the doc: you can use /(?:)/ to -zefram |
From @ppisarOn 2013-07-31, Paul Johnson <paul@pjcj.net> wrote:
I see. Then it's a feature. Never mind. Just if you want to know my use case, the second match uses a regular -- Petr |
From zefram@fysh.orgPetr Pisar wrote:
To provide consistent semantics to the user, you need to process the $perlre = $userre eq "" ? qr/(?:)/ : qr/$userre/; or $perlre = qr/(?:$userre)/; (Compiling the regexp early with qr// is often a good idea.) -zefram |
From @cpansproutOn Wed Jul 31 08:34:08 2013, zefram@fysh.org wrote:
Watch out for qr/$userre/. I fixed that in perl 5.18 (commit -- Father Chrysostomos |
From zefram@fysh.orgFather Chrysostomos via RT wrote:
That's what the conditional in my example is avoiding. -zefram |
From @epaOut of interest is there a performance boost from reapplying the last -- |
From @demerphqOn 1 August 2013 12:38, Ed Avis <eda@waniasset.com> wrote:
Hypothetically a tiny boost. Yves -- |
From @demerphqOn 1 August 2013 13:03, demerphq <demerphq@gmail.com> wrote:
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/) { Or similar constructs. It actually makes no sense that it applies to Yves -- |
From @demerphqOn 1 August 2013 13:08, demerphq <demerphq@gmail.com> wrote:
IMO we should nuke it and replace it with a (*LASTMATCH) metapattern. Yves -- |
From @ap* demerphq <demerphq@gmail.com> [2013-08-01 13:10]:
It makes perfect where this shortcut came from – namely ed, the ancient 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 And even when I say all this, I am almost certainly being ahistorical – (I expect Aaron to come up behind me and embarrass me now. :-) ) * demerphq <demerphq@gmail.com> [2013-08-01 13:10]:
Yes, probably. It made great sense in a text editor and may still make But boy would we need a long deprecation cycle for this one. (It pre- Regards, |
From @arcAristotle Pagaltzis <pagaltzis@gmx.de> wrote:
Nope, your summary pretty much covers it. :-) ed(1) already exists in the First Edition manual (so before November grep(1) came next, in Fourth Edition (so between February and November 1973): http://www.tuhs.org/Archive/PDP-11/Distributions/research/Dennis_v4/v4man.tar.gz In 1975, George Coulouris at Queen Mary College (in London; http://www.eecs.qmul.ac.uk/~gc/history/ vi(1) was originally (in 2BSD, May 1979) a hard link to ex(1); when it sed(1) didn't appear till Seventh Edition, in January 1979: http://plan9.bell-labs.com/7thEdMan/v7vol1.pdf The original diff(1) appeared in Fifth Edition (June 1974), and http://www.tuhs.org/Archive/PDP-11/Distributions/research/Dennis_v5/v5man.pdf As for patch(1), Larry first wrote it in 1984, and published it in https://groups.google.com/forum/#!topic/mod.sources/xSQM63e39YY Now, Ken Thompson wrote the Unix ed(1) in PDP-11 assembler: https://code.google.com/p/unix-jun72/source/browse/trunk/src/cmd/ed2.s This means it can be dated to some time in 1971, according to Dennis Ritchie: http://cm.bell-labs.com/who/dmr/hist.html But it turns out we can rewind a little further. A team at UCB http://web.archive.org/web/20120219114658/http://www.computer-refuge.org/bitsavers/pdf/sds/ucbProjectGenie/mcjones/R-15_QED.pdf It's still possible to see the core of the ed(1) design in that, even Ken Thompson ported qed to CTSS circa 1970, and therefore shortly http://cm.bell-labs.com/cm/cs/who/dmr/qedman.pdf This is much more similar to the ed(1) we know and (presumably) love, So this aspect of Perl can be dated back to code written no later than Enjoy! -- |
From @khwilliamsonOn 08/05/2013 12:09 PM, Aaron Crane wrote:
For the record, I come close. I used to use the qed text editor on a |
From @arcKarl Williamson <public@khwilliamson.com> wrote:
Thank you! AFAICT from Googling, CTSS came first, and Bell Labs had both "Nike http://manpages.bsd.lv/history/canaday_24_10_2011.txt It does seem to rely on the participants' memory, though, so perhaps -- |
From @khwilliamsonOn 08/05/2013 01:10 PM, Aaron Crane wrote:
I remotely used the one from Indian Hill (IH for short; located in a |
From @ap* Aaron Crane <arc@cpan.org> [2013-08-05 20:10]:
Wow, there’s an actual straightforward corner within Unix history. :-)
Which, to be explicit, means it predates Perl (1.0 in 1987) by nearly
I did, thank you. :-) I hadn’t heard of em! Nor qed, of course, but Regards, |
From @epaAaron Crane <arc <at> cpan.org> writes:
I see that Perl's $. variable for the current line number can also be traced -- |
Migrated from rt.perl.org#119095 (status was 'resolved')
Searchable as RT119095$
The text was updated successfully, but these errors were encountered: