
yapp
User
Mar 9, 2002, 1:53 AM
Post #6 of 6
(2799 views)
|
Sorry, I didn't see the $1 (please make it bold or something) The +< sucker (read+write I guess?) requires that the file already exists. Use this instead: [perl] use Fcntl qw(:DEFAULT :flock); sysopen(FH, $file, O_CREAT|O_RDWR) or die "Can't rdwr $file: $!"; flock(FH, LOCK_EX); my @data = <FH>; # modifiy @data; seek(FH, 0, 0) or die "Can't seek to begin: $!"; truncate(FH, 0) or die "Can't erase contents: $!"; print FH, @data; close(FH); [/perl] If you don't want to slurp anything, use a secondfile wherein you store the new contents. (read in $file, write to "$file~"). At the end, seek both files to the begin, start reading from "$file~", and write that back into $file. Don't forget the truncate the $file first! Maybe truncating $file to the size of the "$file~" is a very nice option, since you keep the diskspace reserved. (so it doesn't need re-allocation) Yet Another Perl Programmer _________________________________ ~~> [url=http://www.codingdomain.com]www.codingdomain.com <~~ More then 3500 X-Forum [url=http://www.codingdomain.com/cgi-perl/downloads/x-forum]Downloads!
|