At 12:19 pm -0400 27/05/02, Chris Nandor wrote:
>At 15:49 +0200 2002.05.27, Bart Lateur wrote:
>>Sorry for the late reply. Actually, no, I'm not sorry, I've been away
>>for a few weeks, so it's actually not my fault. :-)
>>
>>On Mon, 13 May 2002 13:04:43 +0200, Axel Rose wrote:
>>
>>>At 14:37 Uhr +0100 06.05.2002, Alan Fry wrote:
>>>>open(IN, $f);
>>>
>>>Problem 1:
>>>open() failes if a filename contains spaces. This is a very
>>>common problem. Even Net::FTP didn't work.
>>>Everybody opening files from the Desktop has to make this
>>>experience.
>>
>>Then use the three argument open(). It's been added to Perl in order to
>>solve this very problem, for one. It's rather new, I'm pretty sure it
>>wasn't in perl 5.004, but it *is* available in 5.6, so with the newest
>>MacPerl, you should be able to use it.
>>
>>The way it works, is that instead of using a combined string with file
>>name and opening mode, you now have them in separate arguments:
>>
>> open(IN, "<", $f);
>>
>>Simple, isn't it?
Somehow I missed Bart's note: hence the silence.
>Yes.
>
>However, two notes:
>
>* open() does *not* fail on a filename with spaces; it fails on a filename
>with leading or trailing spaces.
Right. Many folk put spaces at the beginning of folder names so that
the Finder lists them more tidily. That is the most common problem?
> This works fine, with embedded spaces:
>
> my $f = "Bourque:Desktop Folder:file.txt";
> open F, $f or die $!;
> print scalar readline F;
>
>This does not:
>
> my $f = "Bourque:Desktop Folder:file.txt ";
> open F, $f or die $!;
> print scalar readline F;
For the life of me, and please believe I am not being picky, I can't
see the difference between the two. What am I missing?
>There are many solutions, one of which is three-arg open. Another is to
>use sysread(), which is sometimes a pain.
Particularly if calls to 'sysread()' and 'read()' get inadvertently
mixed on the same filehandle I believe.
>The third is to specify your open sign ('>', '<', etc.) and add a
>trailing null:
>
> my $f = "Bourque:Desktop Folder:file.txt ";
> open F, '<' . $f . "\0" or die $!;
> print scalar readline F;
>
>The greater danger with C< open F, $f > is that the filename might begin
>with a ">" or somesuch. Both three-arg open, and the method above with
>"\0", solve both problems; but the latter method works in any version of
>perl. I am not a big fan of three-arg open, but I have to admit it looks a
>lot nicer. :-)
Frankly a lot of problems would disappear would they not, if spaces
in folder/file names were simply banned for ever to outer darkness?
Alan Fry