-2
A
回答
2
這應該工作,
#!/usr/bin/perl
# File: convert.pl
no utf8; # its not required
while (<>) {
s/(\xa3)/pound/g;
print;
}
因爲£
在我的hexdump上顯示爲0xA3
。
但是,這樣會
#!/usr/bin/perl
while (<>) {
s/£/pound/g;
print;
}
只是說
chmod a+x convert.pl
convert.pl yourfile.html > newfile.html
4
你很可能忘了:
use utf8;
試試下面的程序:
#!/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£.
如果你想從一個名爲input
文件的讀取和寫入名爲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 $_;
}
0
perl -i.bak -ne 's/£/£/g; print $_' file
相關問題
- 1. 如何在Vim中的文件夾中替換所有文件?
- 2. 如何在Perl替換之前替換匹配之前的所有文本?
- 3. 如何用Perl替換文件中的特定IP?
- 4. 如何用Perl替換文件中間的行?
- 5. 如何用Perl替換文件中的完整IP地址?
- 6. 如何用Perl中的bfjpv替換aeiou?
- 7. 替換所有文件夾中
- 8. 如何使用fix_mysql.inc.php文件替換Mysqli的所有MySql函數
- 9. 如何在文件夾中的所有文件中執行文本替換?
- 10. perl搜索和替換目錄中的所有文件的腳本
- 11. 替換Windows中所有子文件夾中的所有文件名#
- 12. 如何用scala中的文字\ d替換所有數字?
- 13. 如何用一個字符替換文本文件中的所有空格?
- 14. ruby equivalent perl命令用於替換文件中的換行符?
- 15. 如何使用Perl列出目錄中的所有文件?
- 16. 如何用Perl中的另一組替換文件中的一組單詞?
- 17. 如何在一堆文本文件中用''替換所有'0xa0'字符?
- 18. 替換項目中所有java文件中的文本
- 19. 如何替換所有「?」使用javascript
- 20. 如何替換Mongo中所有文檔中的字符串
- 21. 如何讀取文件夾中的所有文件並使用Groovy替換文件中的模式
- 22. 用unix命令替換所有文件中的ruby代碼
- 23. HTMLPurifier轉換£回£
- 24. 如何替換我的manifest.json中的文件名使用rev-replace替換文件
- 25. 如何找出在Perl替換中被替換的內容?
- 26. 如何替換使用PHP ereg_replace替換所有特定字符?
- 27. 替換一組文件中的所有文本
- 28. Python:如何用所有文件,文件夾和子文件夾的名稱中的下劃線替換空格?
- 29. 如何用文本行上的空格替換所有星號(*)
- 30. 如何替換對UIWebView有用的html文件中的變量?
顯示你嘗試過什麼,沒有工作,使人們可以看到什麼地方出了錯,並幫助你? – ysth 2009-07-06 08:37:39
你一直在評論「問題是什麼」,但沒有人會告訴你,因爲你沒有說你做了什麼。你想在Vim做這個嗎?如果是這樣,_how_?你想用Perl來做這個嗎?如果是這樣,_how_? – Telemachus 2009-07-06 10:34:44
對不起,它之前,我插入其他評論並刪除它。現在問題得到解決 – joe 2009-07-06 10:37:08