2015-09-02 13 views
-1

我試圖保存一個頁面上有它的Unicode印地文字體。我已經嘗試了幾個從這個網站和其他,但似乎沒有任何工作。試圖用Unicode保存頁面印地文

我得到的錯誤與寬字符有關。

這裏是代碼我使用:

use CGI; 
use strict; 
use warnings; 
use LWP::Simple; 
use utf8; 

use Encode qw(decode); 

    $url = "http://www.vedakosh.com/rig-veda/mandal-1/sukta-001/mantra-rig-01-001-001"; 
    my $content = get $url or die "Couldn't get $url" unless defined $content; 
    my $file="1.html"; 
    open FILE, ">:encoding(UTF-8)", "$file"; 
    print FILE $content; 

不知道我做錯了,可有人請幫助或建議的東西嗎?

+1

請提供確切的錯誤字符串 – pcantalupo

+2

'my $ content = get $ url或死...除非定義$ content;'看起來危險地接近['my $ var = $ x如果$ y'](http://stackoverflow.com/q/2161111)構建。 '$ content'不能在程序中的那個位置定義,所以後綴'unless'是不必要的。 – mob

+1

此代碼不應產生該錯誤。由於未聲明的'$ url'(也可能是'$ content'),它將無法編譯。 –

回答

0

上的文件句柄使用binmode工作對我來說:

use strict; 
use warnings; 

use CGI; 
use LWP::Simple; 

my $url = "http://www.vedakosh.com/rig-veda/mandal-1/sukta-001/mantra-rig-01-001-001"; 
my $content = get $url or die "Couldn't get $url"; 
my $file="1.html"; 

open my $fh, '>', $file 
    or die $!; 

binmode $fh, ':utf8'; 
binmode STDOUT, ':utf8'; 

print $fh $content; 
print $content; 
+0

您提供的解決方案仍然給我相同的結果..不是我想要的結果,Unicode印地文..我想要頁面保存原樣..與印地文字體.. –

0

謝謝大家。我發現的代碼是好的..和犯規進行任何編碼或東西..它得到的頁面權,唯一的問題是源頭本身在頭文件中提到的編碼錯誤,我沒有注意到之前..

但是,謝謝大家。我很感謝你的支持和建議..