On Apr 1, 2006, at 3:49 AM, kurtz le pirate wrote:

mac os x store file name in utf-8 format. so, how to open file with
"special" characters in name ?

The same way you open any file:

        open(FH, '<', $filename) or die "Could not open $filename: $!";

a very simple exemple is a file name that begin with space. if i write :
open(FILE," Read in a file"), perl return an error:
  *** can't open [ Read in a file] : No such file or directory

That error is not because of the space - spaces in file names present no problems to Perl, nor do unicode characters. If you pass a string to an external child shell or other app that assigns special meaning to spaces or other characters, then you'll need to apply whatever escaping rules are needed by that external shell.

i suppose that i do "escpae" chars like terminal do when dragging file
directely in the windows, but how ?

" Read in a file" --> "\ Read\ in\ a\ file"

That's not necessary - spaces don't need to be escaped in strings unless they're going to be passed to an app that requires that.

"Eléments mécaniques" --> "Ele\314\201ments\ me\314\201caniques"

That by itself won't create a UTF8 string - it will simply create a string with the literal ASCII value above. There's a conversion function in 'perldoc utf8' that will do the conversion.

Or, you can 'use utf8' at the top of your code; that tells the Perl interpreter that your script itself is UTF8 encoded. You can then use Unicode characters in your script - and not just in string literals. You can also use Unicode in subroutine, package and variable names, comments, anywhere.

in fact, the strange thing is that it's the "wanted function" of the
File::Find module who return the file name and the file name is not
exploitable :((

The wanted function only gets the file name of the file, which is not enough to open the file with, if it's in a subdirectory. Try calling open() with the full path to the file, not just the file name alone.

sherm--

Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org

Reply via email to