At 7:11 -0700 2004.04.08, Bill Becker wrote:
>I have a bunch of files that all, somehow mysteriously, end with a
>space character x'20'.
>
>BBEdit will open them just fine when double-clicked. But MacPerl
>seems to have a problem with them and insists on removing trailing
>blanks from the name scalar prior to opening.
>
>What's the best way to deal with these pesky file names in MacPerl???

This is in perlfunc's open entry, and some other places, though it is not
altogether obvious.  The basic answer is that plain open() is magic, and
strips out trailing whitespace.

               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 "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: $!";

               Use 3-argument form to open a file with arbitrary weird charac-
               ters in it,

                   open(FOO, '<', $file);

               otherwise it's necessary to protect any leading and trailing
               whitespace:

                   $file =~ s#^(\s)#./$1#;
                   open(FOO, "< $file\0");

I am fairly certain three-arg open works in MacPerl 5.6.1.  If not, the
latter works, although this line:

                   $file =~ s#^(\s)#./$1#;

Would need to be something like this:

                   $file =~ s#^(\s)#:$1#;

And it wouldn't work at the root of the filesystem (if it is an absolute
path and your HD name is " HD", you are out of luck :-).  The final option
would be to use sysopen() instead.

Cheers,

-- 
Chris Nandor                      [EMAIL PROTECTED]    http://pudge.net/
Open Source Development Network    [EMAIL PROTECTED]     http://osdn.com/

Reply via email to