[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Error opening file w/trailing spaces in name



I know what went wrong, but am not sure about the solution.

Excerpt of message (sent 28 January 1999) by Ero Brown:
>  open(THEFILE, "<$theFileName")
> 
> e.g., $theFileName = "Problem File   ";
> 
> What am I doing wrong?

The camel says (page 191):
::    First, any leading and trailing whitespace is removed from the string.

Ouch!  However later it goes on (page 194):
::    In order to open a file with arbitrary weird characters in it,
::    it's necessary to protect any leading and trailing whitespace,
::    like this:
::    
::        $file =~ s#^\s#./$&#;
::        open FOO, "< $file\0";
::    
::    But we've never actually seen anyone use that in a script...

Ok, the first line is very Unixish, where "." means the current
directory, and directories in a path are separated by "/" not ":".
And it deals only with leading spaces, so you don't need that anyway.

The second line relies on the fact that Perl can handle NULs (\0)
embedded in a string, wheras in C it signals the end of any string.
(Under Unix, filenames consist of characters that
**    ... may be selected from the set of all character  values
**    excluding  \0  (null)  and the ASCII code for / (slash).
-- intro(2))

But can a NUL be in a Mac filename?  Will MacPerl support it?
Try it!

	Christian Brechbuehler
	
	Communication Technology Laboratory, Image Science Group
	Swiss Federal Institute of Technology (ETH), Zurich

***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch