At 12:18 +0200 2002.05.28, Bart Lateur wrote:
>On Mon, 27 May 2002 12:19:37 -0400, Chris Nandor wrote:
>
>>There are many solutions, one of which is three-arg open.  Another is to
>>use sysread(), which is sometimes a pain.
>
>I think you must really be talking about sysopen().

Yes.  My brain was mostly on vacation yesterday.

On leading whitespace: perlopentut.pod suggests putting "./" in front of
the filename.  perlopentut.pod is written by tchrist, and is therefore
somewhat bigoted.  :-)  However, you can try:

        require File::Spec;
        if ($file =~ /^\s/ && !File::Spec->file_name_is_absolute($file)) {
                $file = File::Spec->catfile(File::Spec->curdir(), $file);
        }
        open F, "< $file\0" or die $!;

This won't save you if the path is absolute and your volume name begins
with a space.  So Don't Do That.  Don't put a space at the beginning of
your volume name, and don't put slashes in paths, and don't name a volume
"Dev".

Additionally, almost all relative paths begin with ":" anyway, if there is
a directory in the path, so you only need to worry about volume names and
single files in cwd (that is, when opening "file.txt" in the current
directory) for this.  Often those will begin with ":" too.  It's really not
a big problem, but it does bite people sometimes.  Droplets pass full
paths, so that's not much of a problem.

All that said, perl 5.8 is coming out soon, so I don't think assuming 5.6
or better is a big deal.  ;-)  But if you really want to be safe, and go
back to older perls, you could also consider the bloated but useful
IO::File, which, somewhat to my surprise, uses the very
file_name_is_absolute() trick I used above when passing in the mode
separately (e.g., open($file, '<')).  Great minds and all that.  ;-)

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

Reply via email to