I'm guessing seek won't go past the end of the file, you'll have to add
logic to add "empty" records to your file in order to go that far. It is
unclear from the Perl documentation on seek (as well as "man fseek") that
this is the behavior, but it seems rational and the most likely reason for
what you're experiencing.
Psudeo code:
Is seek position past EOF?
For each record past EOF
Add blank record to EOF
Seek position
Write new record
-Wayne Simmons
--
Software Engineer
InterSystems USA, Inc.
303-858-1000
-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Barry
Brevik
Sent: Friday, July 17, 2009 1:02 PM
To: [email protected]
Subject: Help with file stuff
I'm creating a file which is just an ASCII text file, but I'm writing
fixed length records into it. At any time, I need to reopen the file and
write a record to a byte position calculated at run time. The write
position will frequently be beyond the end of the current file length,
so I need for the file to be extended.
In the test code below, I have replaced the calculated position with
"128" for convenience. When I run the code, it creates the file, and it
says that the current position is "128", but when I write the record, it
always ends up at the very beginning of the file.
Any clue as to what I am doing wrong?
------------------------------------------
use warnings;
$MAILSTATS = '+>>mailstats.dat';
if (open MAILSTATS)
{
if (seek MAILSTATS, 128, 0)
{
print "Current file position is ", tell(MAILSTATS), "\n";
print MAILSTATS "This is a test record.";
}
else
{
print " Can not seek to location 128.\n";
}
close MAILSTATS;
}
_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs