#151 IO::File + leading space for hard disk

Release 5.6.1r*
Axel Rose

The following failes:

use IO::File;
my $file = ' myharddisk:folder:filename';
my $fh = IO::File->new;
$fh->open( '$file', "r" ) or die "unable to open'$file' - $!";

Note the leading space in the hard disk name " myharddisk".



  • Chris Nandor

    Chris Nandor - 2003-01-09
    • labels: --> Standard Library (Modules)
    • status: open --> open-accepted
  • Chris Nandor

    Chris Nandor - 2003-01-09

    Logged In: YES

    A bug in IO::File. It does this in open():

    if (! File::Spec->file_name_is_absolute($file)) {
    $file =
    $file = IO::Handle::_open_mode_string($mode) . "
    open($fh, $file);

    For detail, see the documentation for open in perlfunc and
    in IO::File for a discussion of protecting whitespace in a
    path. Normally, open() removes leading and trailing
    whitespace. The problem is that the only method they gave
    for protecting leading whitespace, apart from using the
    three-arg form of open(), is to put "./" or something in
    front of the relative path. This assumes that whitespace
    cannot be in front of an absolute path; as such, there's no
    way (that I know of) to use the two-arg form with such a path.

    I'll think on a patch; until then, the only workarounds are
    to patch it yourself, rename the volume, use open() instead
    of IO::File->open(), or use numeric modes, such as:

    my $file = ' MyDisk:foo';
    my $fh = IO::File->new;
    $fh->open($file, O_RDONLY) or die "unable to open
    '$file': $!";

    The numeric modes in IO::File use sysopen(), which is not
    magic like open() is.

  • Chris Nandor

    Chris Nandor - 2003-01-09
    • milestone: --> Release 5.6.1r*
    • priority: 5 --> 7
    • assigned_to: nobody --> pudge

Log in to post a comment.