Re: openning file...
In article [EMAIL PROTECTED], [EMAIL PROTECTED] (Sherm Pendley) wrote: 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. sory but you're wrong. File::Find doc say : ...you are chdir()'d to$File::Find::dir when the function is called,unless no_chdir was specified. thanks -- klp
Re: openning file...
On Apr 1, 2006, at 2:49 AM, kurtz le pirate wrote: hello, mac os x store file name in utf-8 format. so, how to open file with special characters in name ? 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's just because open() trims whitespace from the front of the argument. See the open() docs in perlfunc: -- ... The filename passed to 2-argument (or 1-argument) form of open() will have leading and trailing whitespace deleted, and the normal redirection characters honored. This property, known as magic open, can often be used to good effect. A user could specify a filename of Frsh cat file |, or you could change certain filenames as needed: $filename =~ s/(.*\.gz)\s*$/gzip -dc $1|/; open(FH, $filename) or die Can't open $filename: $!; Use 3-argument form to open a file with arbitrary weird characters in it, open(FOO, '', $file); otherwise it's necessary to protect any leading and trailing whitespace: $file =~ s#^(\s)#./$1#; open(FOO, $file\0); ... -- The 3-argument form of open() is definitely preferred. -Ken
Re: openning file...
On 2006.4.2, at 10:34 PM, kurtz le pirate wrote: In article [EMAIL PROTECTED], [EMAIL PROTECTED] (Sherm Pendley) wrote: 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. sory but you're wrong. File::Find doc say : ...you are chdir()'d to$File::Find::dir when the function is called,unless no_chdir was specified. thanks -- klp mind-boggling
Re: openning file...
In article [EMAIL PROTECTED], [EMAIL PROTECTED] (Ken Williams) wrote: On Apr 1, 2006, at 2:49 AM, kurtz le pirate wrote: hello, mac os x store file name in utf-8 format. so, how to open file with special characters in name ? 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's just because open() trims whitespace from the front of the argument. See the open() docs in perlfunc: -- ... The filename passed to 2-argument (or 1-argument) form of open() will have leading and trailing whitespace deleted, and the normal redirection characters honored. This property, known as magic open, can often be used to good effect. A user could specify a filename of Frsh cat file |, or you could change certain filenames as needed: $filename =~ s/(.*\.gz)\s*$/gzip -dc $1|/; open(FH, $filename) or die Can't open $filename: $!; that is i found too !! Use 3-argument form to open a file with arbitrary weird characters in it, open(FOO, '', $file); otherwise it's necessary to protect any leading and trailing whitespace: $file =~ s#^(\s)#./$1#; open(FOO, $file\0); humm... in the wanted function i write : 065: sub process { 066:if (-f $_) { 067: $_ =~ s/ /\ /g; 068: my $thisSize = stat($_)-size; 069: if($thisSize0) { 070:if (open (INPUT,,$_)) { 071:... ... and that works. what think about it? -- The 3-argument form of open() is definitely preferred. yes. i always use this form. when i post, i think about about chars problems... -Ken thanks -- klp
openning file...
hello, mac os x store file name in utf-8 format. so, how to open file with special characters in name ? 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 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 Eléments mécaniques -- Ele\314\201ments\ me\314\201caniques 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 :(( thanks -- klp
Re: openning file...
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
Re: openning file...
At 11:51 am -0500 1/4/06, Sherm Pendley wrote: 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 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. Here's an example: #!/usr/bin/perl binmode STDOUT, :utf8; $desk = $ENV{HOME}/desktop; $name = Eléments mécaniques; $f = $desk/$name; open F, $f or die $!; print F Réussi !\n; close F; open F, :encoding(utf8), $f; print F; JD