I'm having problems while replacing metacharacters using regular expressions. The phrase I want the regular expressions replace the metacharacter is:
ley+sobre+propiedad+literaria+1847
And the code I use is that below:
$file =~ s/\+/\s/; # --> Replace the +
But it seems to only replace the first metacharacter and the result is:
leysobre+propiedad+literaria+1847
What shoud I use?
\s
is a character class and not a valid escape for strings. The second part of a substitution is taken as a string./g
switch on the replacement.tr///
operator.Assuming you want to replace +
by a space:
tr/+/ /;
or
s/\+/ /g;
If you want to decode URLs:
use URL::Encode 'url_decode';
my $real_filename = url_decode $file;
See the documentation for URL::Encode for further information.