Re: edit / seek woes
- From: japhy@xxxxxxxxxxxx (Jeff 'japhy' Pinyan)
- Date: Mon, 29 Aug 2005 09:44:11 -0400 (EDT)
On Aug 29, Brent Clark said:
Would someone be so kind as to please over look me code and if possible, point out where I am going wrong.
Would you be so kind as to explain what happens with it that you didn't expect to happen? (Or what doesn't happen that you'd expected to happen.)
open(HDATFILE, "+< $fileName.dat") or die "Cant open file $fileName.dat $!"; flock (HDATFILE, LOCK_EX) or die "Cant lock file $fileName.dat $!";
Make sure you're including the Fcntl module for the LOCK_EX constant.
my $writePos = 0; while (<HDATFILE>){ my $readPos = tell HDATFILE;
if(m/^p11[016]/io){
$found110 = 'y' unless m/^p110/i; $found111 = 'y' unless m/^p111/i; $found116 = 'y' unless m/^p116/i;
seek HDATFILE, $writePos, 0; print HDATFILE &compareRmNames($fileName, $_); $writePos = tell HDATFILE; seek HDATFILE, $readPos, 0;
Unless you are writing the EXACT SAME NUMBER OF BYTES to the file, you are going to either over-write or under-write content.
You're probably better off using a temporary file, or Perl's "in-place" editing.
-- Jeff "japhy" Pinyan % How can we ever be the sold short or RPI Acacia Brother #734 % the cheated, we who for every service http://japhy.perlmonk.org/ % have long ago been overpaid? http://www.perlmonks.org/ % -- Meister Eckhart .
- References:
- edit / seek woes
- From: Brent Clark
- edit / seek woes
- Prev by Date: Re: Find first day of every week in a month
- Next by Date: Re: open and edit file to prevent race conditions
- Previous by thread: edit / seek woes
- Next by thread: RE: system ("cd ..")
- Index(es):