Reputation: 231
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";
Upvotes: 7
Views: 1217
Reputation: 943571
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.
$x = "I like dogs.";
$y = $x;
$y =~ s/dogs/cats/;
print "$x $y\n";
Or you could use the idiomatic "one-liner":
$x = "I like dogs.";
($y = $x) =~ s/dogs/cats/;
print "$x $y\n";
Upvotes: 10
Reputation: 56059
I'm using the same version (on Linux) and getting the same error plus
Unquoted string "r" may conflict with future reserved word
and it works when I remove r. That tutorial is from 5.14, it may be that the r
feature wasn't yet implemented in 5.12.
Upvotes: 2