Be careful, it isn't actually a regex; it is a string that will be compiled to a regex. You can see one difference here:
#!/usr/bin/perl use v5.20; use warnings; say "string matches:"; for my $s ("foo", "AfooZ") { say "\t$s: ", $s =~ "\Afoo\Z" ? "true" : "false"; } say "regex matches:"; for my $s ("foo", "AfooZ") { say "\t$s: ", $s =~ /\Afoo\Z/ ? "true" : "false"; } which outputs Unrecognized escape \A passed through at t.pl line 8. Unrecognized escape \Z passed through at t.pl line 8. string matches: foo: false AfooZ: true regex matches: foo: true AfooZ: false To my knowledge, the only delimiters that do not require m or qr before them are // and ??; however, they are not equivalent (and ?? must be m?? as of Perl 5.22). The m?? operator only matches the first time it sees a pattern and then will not match again until reset is called: #!/usr/bin/perl use v5.18; use warnings; for ("fo", "foo", "fooo", "foooo") { my ($match) = ?(fo+)?; say $match // "no match"; if (/fooo/) { reset; } } Which outputs Use of ?PATTERN? without explicit operator is deprecated at t.pl line 7. fo no match no match foooo On Thu, Feb 23, 2017 at 6:53 PM Andrew Solomon <and...@geekuni.com> wrote: > Thanks Uri! > > On Thu, Feb 23, 2017 at 10:32 PM, Uri Guttman <u...@stemsystems.com> wrote: > > On 02/23/2017 05:19 PM, Andrew Solomon wrote: > > Running Perl 18.2 I was surprised to discover that I can use single and > double quotes as regex delimiters without the 'm' operator. > > For example, instead of writing > > "/usr/bin/perl" =~ m"/perl" > > I can just write > > "/usr/bin/perl" =~ "/perl" > > Can anyone point me to the documentation indicating which delimiters don't > need the 'm' operator? > > > you actually are thinking in the wrong direction. the =~ operator causes > its right side to always be a regex unless the s/// or m// or tr/// ops are > seen there. you can even use an expression or sub call or anything on the > right of =~ and it will be parsed as a regex (if no op is there as i just > said). > > you can easily check this out with something simple like "/usr/bin/perl" > =~ "/pe" . "rl". > > so it isn't the delimiters as you think but the =~ op itself that makes it > a regex. > > uri > > -- > To unsubscribe, e-mail: beginners-unsubscr...@perl.org > For additional commands, e-mail: beginners-h...@perl.org > http://learn.perl.org/ > > > > > > -- > Andrew Solomon > > Mentor@Geekuni http://geekuni.com/ > http://www.linkedin.com/in/asolomon >