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 > F<"rsh 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($thisSize>0) { 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