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

Re^2: Weird encoding after grabing filenames

by Nik
on Jun 16, 2009 at 20:27 UTC ( #772134=note: print w/replies, xml ) Need Help??

in reply to Re: Weird encoding after grabing filenames
in thread Weird encoding after grabing filenames

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?
  • Comment on Re^2: Weird encoding after grabing filenames

Replies are listed 'Best First'.
Re^3: Weird encoding after grabing filenames
by ikegami (Pope) on Jun 16, 2009 at 20:53 UTC

    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 :-)
Re^3: Weird encoding after grabing filenames
by graff (Chancellor) on Jun 16, 2009 at 20:53 UTC
    When I visited your web page (, 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?

        Because some characters are encoded the same in both ISO-8859-7 and UTF-8. So even though you program was buggy, you still happened to get some correct output.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://772134]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (6)
As of 2017-06-26 16:29 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (583 votes). Check out past polls.