As I understand it, these options will all effectively be turned on by default in the Perl 6 regex engine. So either Larry has decided that they are, in fact, best practice or Damian has sneaked them into the specs whilst Larry wasn't watching.
Firstly, Perl 6 is not Perl 5.
Secondly, Perl 6 gives you \N, a convenient way to write <-[\n]> (that's [^\n]). It's worse than ., but acceptable. Writing [^\n] all the time is a hard exercise for one's fingers, and makes for messy code. That's why I strongly believe you should only use /s when you really want . to include the newline character.
/m won't be turned on by default in Perl 6. Instead, we get different metacharacters for begin/end of line versus string. So again it gives best of BOTH worlds.
As for /x... I have no strong opinion about that. I don't think /\A\d+\z/ is unreadable, but I don't mind /\A \d+ \z/x at all.
| [reply] |
| [reply] |
| [reply] |
use Regexp::SlashN;
"A
B
C" =~ /(\N+)/;
$1 eq "A
B
C" or die;
Regexp/SlashN.pm package Regexp::SlashN;
use overload;
sub import { overload::constant qr => \ &convert }
# A simple table of definitions
my %syntax = ( '\\' => '\\',
N => '[^\n]', );
sub convert {
my ( $re ) = @_;
$re =~ s/\\([\\N])/$syntax{$1}/g;
return $re;
}
| [reply] [d/l] [select] |