1

While trying to debug an issue I am having with git-svn and the --ignore-paths option, I've run into this perl expression that I don't understand and haven't been able to find anything similar in perl documentation.

$path =~ m!$self->{ignore_regex}! 

My understanding of this is that this is matching the $path string to the ignore_regex but it doesn't seem to match anything the way I expect. The part that I don't understand is the m! ! around $self->{ignore_regex}?

How should I be reading this syntax?

dk.
  • 937
  • 1
  • 10
  • 12
  • 4
    `m!....!` is the same as `/.../`, the `!` just confines the regex. See the documentation for [Regexp Quote-Like Operators](https://perldoc.perl.org/perlop#Regexp-Quote-Like-Operators). – Steffen Ullrich Mar 18 '21 at 18:07
  • 1
    You don't even need the `m!!` for this expression. – simbabque Mar 18 '21 at 18:21

1 Answers1

4

This is the match operator.

m!...! is more commonly written as /.../, but they are 100% identical.

If "/" is the delimiter then the initial m is optional. With the m you can use any pair of non-whitespace (ASCII) characters as delimiters. This is particularly useful for matching path names that contain "/", to avoid LTS (leaning toothpick syndrome). [...]

For example, the following are identical:

$path =~ /$self->{ignore_regex}/
$path =~ m/$self->{ignore_regex}/
$path =~ m^$self->{ignore_regex}^
$path =~ m{$self->{ignore_regex}}

The code in question checks if the string in $path matches the regex pattern in $self->{ignore_regex}.

ikegami
  • 367,544
  • 15
  • 269
  • 518