N
news
I wouldn't be surprised if I'm doing something stupid here, but for the
life of me I can't see it.
Compare the following two snippets, which write and then rewrite a
sample file.
1. IO::Open and setpos
use IO;
use Fcntl;
use strict;
unlink "/tmp/x"; # Testing
my $h = new IO::File "+>/tmp/x" or die "IO::File: $!\n";
$h->print ("hello, world\n") or warn "hello: $!\n";
$h->setpos (0) or warn "setpos: $!\n";
$h->print ("goodbye\n") or warn "goodbye: $!\n";
$h->close or warn "close: $!\n";
2. open and seek
unlink "/tmp/x"; # Testing
open H, "+>/tmp/x" or die "open: $!\n";
print H "hello, world\n" or warn "hello: $!\n";
seek H, 0, 0 or warn "seek: $!\n";
print H "goodbye\n" or warn "goodbye: $!\n";
close H or warn "close: $!\n";
In case (1) I get "setpos: Invalid argument". Case (2) works.
Originally I had read the documentation for setpos to require the
following line, but that just generated a runtime usage error.
$h->setpos (0, SEEK_SET) # with Fcntl qw/EFAULT :seek/
Any suggestions, please? I'd prefer to use IO::File syntax, since it
gives me a little more flexibility and convenience. I've perl version
5.6.1 here.
Cheers,
Chris
life of me I can't see it.
Compare the following two snippets, which write and then rewrite a
sample file.
1. IO::Open and setpos
use IO;
use Fcntl;
use strict;
unlink "/tmp/x"; # Testing
my $h = new IO::File "+>/tmp/x" or die "IO::File: $!\n";
$h->print ("hello, world\n") or warn "hello: $!\n";
$h->setpos (0) or warn "setpos: $!\n";
$h->print ("goodbye\n") or warn "goodbye: $!\n";
$h->close or warn "close: $!\n";
2. open and seek
unlink "/tmp/x"; # Testing
open H, "+>/tmp/x" or die "open: $!\n";
print H "hello, world\n" or warn "hello: $!\n";
seek H, 0, 0 or warn "seek: $!\n";
print H "goodbye\n" or warn "goodbye: $!\n";
close H or warn "close: $!\n";
In case (1) I get "setpos: Invalid argument". Case (2) works.
Originally I had read the documentation for setpos to require the
following line, but that just generated a runtime usage error.
$h->setpos (0, SEEK_SET) # with Fcntl qw/EFAULT :seek/
Any suggestions, please? I'd prefer to use IO::File syntax, since it
gives me a little more flexibility and convenience. I've perl version
5.6.1 here.
Cheers,
Chris