Perl RegEx syntax error

the following code snippet taken from http://perldoc.perl.org/perlrequick.html#Search-and-replace gives me

Found a table where the operator was waiting in line blub.pl 2, next to "S / dogs / cats / g"

What is the problem? I am using Perl 5.12.4 on Windows XP.

the code:

$x = "I like dogs."; $y = $x =~ s/dogs/cats/r; print "$x $y\n"; 
+7
source share
2 answers

You are looking at the documentation for Perl 5.14. This example does not appear in the documentation for Perl 5.12 .

You can see that it is marked as a new feature in perl 5.13.2 delta .

You can copy a variable and then modify it to achieve the same effect in older versions of Perl.

 $x = "I like dogs."; $y = $x; $y =~ s/dogs/cats/; print "$x $y\n"; 

Or you can use the idiomatic "single line":

 $x = "I like dogs."; ($y = $x) =~ s/dogs/cats/; print "$x $y\n"; 
+10
source

I use the same version (on Linux) and get the same error plus

Uncalled string "r" may conflict with future reserved word

and it works when I delete r. This tutorial is from 5.14, it is possible that the function r is not yet implemented in 5.12.

+2
source

All Articles