the following code snippet taken from http://perldoc.perl.org/perlrequick.html#Search-and-replace gives me
Bareword found where operator expected at blub.pl line 2, near
“s/dogs/cats/r”
What’s the problem here? I’m using Perl 5.12.4 on Windows XP.
Code:
$x = "I like dogs.";
$y = $x =~ s/dogs/cats/r;
print "$x $y\n";
You are looking at the documentation for Perl 5.14. That example does not appear in the documentation for Perl 5.12.
You can see that it is marked as a new feature in the perl 5.13.2 delta.
You can copy the variable and then modify it to achieve the same effect in older versions of Perl.
Or you could use the idiomatic “one-liner”: