Beefy Boxes and Bandwidth Generously Provided by pair Networks Joe
laziness, impatience, and hubris
 
PerlMonks  

Write utf-8 to file?

by einerwitzen (Sexton)
on Feb 18, 2004 at 14:37 UTC ( [id://330027]=perlquestion: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.

einerwitzen has asked for the wisdom of the Perl Monks concerning the following question:

I have a form with a text area that when a person types in content and submits it, it saves the content to a file that is read from a page through SSI. The page is fully capable of viewing/showing utf 8 characters.

What I would like to learn is how to make it possible to have the perl script receive the utf-8 text (the language is actually tajik) and post them accurately.

I don't know where to begin on this, any help is appreciated!

Replies are listed 'Best First'.
Re: Write utf-8 to file?
by borisz (Canon) on Feb 18, 2004 at 15:04 UTC
    Tell the form that you like the data in utf-8 with the accept_charset attribute. At best deliver the page with the form already in utf-8 since some browsers send the data back in the charset they receive the data. Now save the file with open my $fh, ">:utf8", $filename or die $!; read it in with open my $fh, "<:utf8", $filename or die $!;
    Boris
      I used
      open(PAGE, "<:utf8", "$news"); @HTML = <PAGE>; print escapeHTML(join '', @HTML); close PAGE;
      And it doesn't work, @HTML is empty. Maybe just a syntax error but i wouldnt know!
        Im sure $news is not found or you have no permissions to read the file. try
        open(PAGE, "<:utf8", "$news") or die "OPEN $news failed ($!)";
        and look into your errorlog file.
        Boris
      Ok i realized that it wasn't working because it wasn't saving properly in the utf8 format.
      open(PAGE, ">:utf8", "$news"); print PAGE @cont; close(PAGE);
      isn't working right. ???
        It works fine, but only with perl 5.8. You should really check for errors. And I prefere my vars for the filehandle. It is good practice and you can yse them to.
        open (my $page, ">:utf8", $news) or die $!; print $page @xxxx; close $page;
        Boris
        I had checked for errors, but when it didn't work it didn't print errors either so i took it out to make it as simple as possible. Yet another problem then, What about for perl 5.6.1 it is what my host has installed.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://330027]
Approved by kutsu
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.