in reply to Re: Re: Re: what function of this Regular Expression?
in thread what function of this Regular Expression?
The reason for the observed behaviour is that a regex with "s as the delimiter get interpolated as a string, before it gets treated as a regex.
I think that the docs are simply out of date or perhaps somewhat badly phrased. Any expression on the right-hand side of =~ or !~ is treated as a regex.
print 'String contains a zero' if '0' =~ 0; String contains a zero $_ =~ join '|', 0, 1 and print "'$_' contains a '0' or a '1'" for qw[ 0 2 50 02 1 11 abc1 def]; '0' contains a '0' or a '1' '50' contains a '0' or a '1' '02' contains a '0' or a '1' '1' contains a '0' or a '1' '11' contains a '0' or a '1' 'abc1' contains a '0' or a '1' $_ !~ join '|', 0, 1 and print "'$_' doesn't contains a '0' or a '1'" for qw[ 0 2 50 02 1 11 abc1 def]; '2' doesn't contains a '0' or a '1' 'def' doesn't contains a '0' or a '1'
The only time the 'm' or '/'s are required is when implicitly comparing against $_.
|
|---|