I am trying to replace all £
symbols in a HTML file with £
. My regular expression does not seem to work.
Could you please help?
I am trying to replace all £
symbols in a HTML file with £
. My regular expression does not seem to work.
Could you please help?
You most probably forgot to:
use utf8;
Try the following program:
#!/usr/bin/perl
use strict;
use warnings;
use utf8;
while (<DATA>) {
s/£/£/g;
print
}
__END__
This is sample text with lots of £££!
50£ is better than 0£.
If you want to read from a file named input
and write to a file named output
:
#!/usr/bin/perl
use strict;
use warnings;
use utf8;
open my $input, '<', 'input' or die $!;
open my $output, '>', 'output' or die $!;
binmode $input, ':utf8';
while (<$input>) {
s/£/£/g;
print $output $_;
}
This should work,
#!/usr/bin/perl
# File: convert.pl
no utf8; # its not required
while (<>) {
s/(\xa3)/pound/g;
print;
}
since £
showed as 0xA3
on my hexdump.
But, so will
#!/usr/bin/perl
while (<>) {
s/£/pound/g;
print;
}
Just say
chmod a+x convert.pl
convert.pl yourfile.html > newfile.html