Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Weird encoding after grabing filenames

by moritz (Cardinal)
on Jun 16, 2009 at 19:48 UTC ( [id://772128]=note: print w/replies, xml ) Need Help??


in reply to Weird encoding after grabing filenames

print "Content-Type: text/html\n\n";

Always include the encoding, ie Content-Type: text/html; charset=utf-8\n\n (or let CGI generate that for you, you use it anyway).

Also you have to pass a scalar as the first argument to from_to, not an array. Read the docs for usage information.

Replies are listed 'Best First'.
Re^2: Weird encoding after grabing filenames
by Nik (Initiate) on Jun 16, 2009 at 20:27 UTC
    yes i do use the cgi equivalent in longer scripts that is 'print header( -charset=>'utf-8' );'

    Yes but i need to re-encode all filenames(@menu_files) to utf-8 at one step, can't it be done without a repeatiton loop?
    Why the path of files is taken correctly while the filaname appears like this?

      can't it be done without a repeatiton loop?

      You want to repeat an action without a loop?

      Well, I suppose you could do

      from_to($menu_files[0], 'ISO-8859-7', 'UTF-8') if @menu_files >= 1; from_to($menu_files[1], 'ISO-8859-7', 'UTF-8') if @menu_files >= 2; from_to($menu_files[2], 'ISO-8859-7', 'UTF-8') if @menu_files >= 3; from_to($menu_files[3], 'ISO-8859-7', 'UTF-8') if @menu_files >= 4; die("Need more!") if @menu_files >= 5;

      Does it count as a loop if the repeating is done by the person rather than the computer?

      Or if all you want to do is hide the loop

      sub from_to_multi { my $fr = shift; my $to = shift; from_to($_, $fr, $to) for @_; } from_to_multi('ISO-8859-7', 'UTF-8', @menu_files);

      But then you end up with two loops. One to place the elements on the stack, and one to process the elements on the stack.

        I'a, really sorry now you are right to accuse me of not expressign myself correctly to what i need to do.
        The way i should have asked would be "How to change this line Encode::from_to(@menu_files, 'ISO-8859-7', 'utf8') since it's first argument cannnot be an array, to a repeatition structure that could take place in only an one line which is Encode::from_to($_, 'ISO-8859-7', 'utf8') for (@menu_files); and not like the following:
        for $menu_file (@menu_files) { Encode::from_to($menu_file, 'ISO-8859-7', 'utf8'); }
        I'am sorry sometimes i need to say what i want in a short kind of a way, so to avoid posting too many lines but i fail to do it properly when i hurry(an yesterday i was ansering at many threads at many forums).I'd be more carefull in future.

        Don't take this as an insult, but hopefully one, Graff, understood what i meant :-)
      When I visited your web page (http://tech-nikos.gr/cgi-bin/test.pl), I was able to get a sensible display by telling my browser to treat the page as iso-8859-7 (greek). But I gather you want the text to be in utf8, which I think would be a good idea.

      As you follow moritz's good advice, you have to respect the docs regarding Encode::from_to(). Here's an easy way to do the required loop in a single line of code:

      Encode::from_to($_, 'ISO-8859-7', 'utf8') for (@menu_files);
      The reason why the path strings are showing up fine is because they are just plain ascii characters; it's only the file names that are non-ascii, and if the web server and browser don't agree on what the encoding is for those non-ascii characters, it's just noise.

      (updated to fix grammar in first sentence)

        Thank you very much that was waht i needed.

        Allow me to ask this: Why only the path strings were plain ascii chars and the filenames were non-ascii which lead me to the extra use of Encode::from_to() to show it properly?

        Does it has to do with the way(type of encoding) Vista encoded its filenames? And if this is the case here why encode the folders differently?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://772128]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2024-04-20 03:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found