Re: RFC 332 (v1) Regex: Make /$/ equivalent to /\z/ under the '/s' modifier
In [EMAIL PROTECTED], Bart Lateur writes: :I'll try to find that "thread" back. This was my message: http://www.mail-archive.com/perl6-language-regex%40perl.org/msg00354.html :I don't think changing /s is the right solution. I think this will :incline people to try and fix their problems by adding /s, without :realising that this changes the definition of every . in their :regexp as well. : :Perhaps. I do think that, in general, textual data falls into one of :three categories: : : * text with possibly embedded newlines : * text with no embedded newlines : * text with an irrelevant newline at the very end. : :The '/s' option is for the 1st case. No '/s' for the 3rd. As for #2: you :don't care. I'd distinguish the first case further into 'the newlines are significant' or not - /s is often desired for the first case, and /m often for the second. And then I'd be tempted to repeat the whole list, replacing 'newline' with 'record separator'. I have to say I'm quite prejudiced against /s - I consider myself reasonably knowledgeable about regexps, but on average about once a month I find myself unsure enough about which is /m and which is /s that I need to check the top of perlre to be sure. I think we've appreciated for some time that it was a mistake to name them as if they were opposites, but if anything I'd like to reduce the need for them rather than to increase it. Hugo
Re: RFC 332 (v1) Regex: Make /$/ equivalent to /\z/ under the '/s' modifier
Is $$ the only alternative, or did I miss more? I don't think I've even seen this $$ mentioned before? $$ is not a suitable alternative. It already means the current process ID. It really cannot be messed with. And ${$} is identical to $$ by definition. I still like the idea of $$, as I described it in the original thread. I've seen no comments for or against at this time. See above. I can't see how yet another alternative, /$$/, is any better than what we have now: /\z/. I agree. If it's more alternatives we're after, just have the person write a custom regex. The idea is to make Perl do the right thing, whatever that may be. The big problem with changing $, as you note, is for people that need to catch multiple instances in a string: $string = "Hello\nGoodbye\nHello\nHello\n"; $string =~ s/Hello$/Goodbye/gm; Without $, you can workaround this like so: $string =~ s/Hello\n/Goodbye\n/gm; My suggestion would be: 1. Make $ exactly always match just before the last \n, as the RFC suggests. 2. Introduce some new \X switch that does what $ does currently if it's deemed necessary. We're back to new alternatives again, but the one thing this buys you is a $ that works consistently. I don't think many people need $'s current functionality, and those that do can have an new \X. -Nate