Subject: | append open in OO interface fails to work, crude patch made |
I tried to do an open using the OO interface, with append. The source
code says ">>" should work. I include a
test script. I got
"Use of uninitialized value in subroutine entry at
C:/Perl/site/lib/Win32API/File.pm line 658."
No file was created. The handle was never made since the regexp left one
of the >s still in the path.
I am using Perl 5.10.0 Win32API:File 0.1101 .
I made a crude patch to allow append to work with the OO interface.
The patch has more info on the bugs.
Show quoted text
__________________________________________________________
#!/usr/bin/perl -w
use strict;
use Win32API::File;
my $file = new Win32API::File '>> C:\Documents and
Settings\Owner\Desktop\somefile.txt';
$file->print('hello'.$$);
$file->close();
Subject: | file.pm.patch |
--- file.pm.old 2008-11-17 19:11:46.000000000 -0500
+++ file.pm 2010-09-23 10:06:49.640625000 -0400
@@ -612,7 +612,9 @@
# FIXME: this needs to parse the full Perl open syntax in $expr
my ($mixed, $mode, $path) =
- ($expr =~ /^\s* (\+)? \s* (<|>|>>)? \s* (.*?) \s*$/x);
+ #in the open mode capture, '>' will evaluate and match before '>>'
+ #so order was reversed to test for '>>' first
+ ($expr =~ /^\s* (\+)? \s* (<|>>|>)? \s* (.*?) \s*$/x);
croak "Unsupported open mode" if not $path;
@@ -624,12 +626,22 @@
} elsif($mode eq '>') {
$access = 'w';
}
+ #without this elsif createFile will truncate the file
+ elsif ($mode eq '>>')
+ {
+ $access = 'wk';
+ }
my $w32_handle = createFile($path, $access);
$self->win32_handle($w32_handle);
- $self->seek(1,2) if $append;
+ #why is position 1? it will just put in a \0 in the skipped char
+ #if I use the below line, I get "Not a GLOB reference at C:/Perl/lib/IO/Seekable.pm line 115."
+ #if $mode is '>>', why IDK, $self->seek works fine if $mode is '>'
+ #crude fix is to call Win32API::File's seek method directly without going through IO::
+ #$self->seek(1,2) if $append;
+ SEEK($self, 0, 2) if $append;
$self->_access($access);
$self->_append($append);