Re: print WWW::Mechanize content (whether in utf8 or not) to file
[email protected] (Shlomi Fish) Fri, 19 Aug 2011 11:17:16 +0300
| Newsgroups | perl.libwww |
|---|---|
| Message-ID | <[email protected]> |
On Thu, 18 Aug 2011 20:51:21 -0500 Peng Yu <[email protected]> wrote: > Hi, > > $browser is an object of WWW::Mechanize. I'm do not completely > understand the differences between different charsets. But I'm > wondering if I should always check the charset in the header of an > HTTP response to determine what binmode FILE should be. Or it is safe > to always use ":utf8"? > > open FILE,">$content_file"; You should write that as: open my $fh, '>', $content_file or die "Cannot open '$content_file' - $!"; See: http://perl-begin.org/tutorials/bad-elements/ > binmode FILE, ':utf8'; > print FILE $browser->content; Preferably do: print {$fh} instead of: print $fh So it will be easier to distinguish. Regards, Shlomi Fish > close FILE; > -- ----------------------------------------------------------------- Shlomi Fish http://www.shlomifish.org/ List of Portability Libraries - http://shlom.in/port-libs XSLT is the number one cause of programmers’ suicides since Visual Basic 1.0. Please reply to list if it's a mailing list post - http://shlom.in/reply .