[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] search and replace a specific line in a file.



Ernesto,
cc: MacPerlers,

One cannot do what you want to do with standard, buffered I/O on
either UNIX or MAC.

One can only append to the normal ASCII text file or re-write it
from scratch.

If one did get the file writing pointer back to the the place
where you read the line from in the middle of the file, the rest
of the file would be truncated anyway, with standard, buffered
I/O.

One can use operating-system I/O calls to do byte-level I/O, but
they would be machine-dependent and are beyond my expertise.

It's possible you are really trying to maintain a database sort
of file -- you might see if the any of the perl libraries with
'db' in the name would help you easily solve your problem.

You might do another post explaining if you have fixed length
records, a 'database' sort of application, etc.  And someone
else could help you better than I.

ERNESTO GONZALEZ thoughtfully keystroked:
|> 
|> I am writing a CGI that searches a flat file for a line that matches a
|> specified string.  What I want to do when I find the line is to manipulate
|> some of the contents and then write the line back to the file at the same 
|> line number.  I am able to do everything except for the print to the file
|> at the right spot (it just appends to the file).  I have the Camel book
|> and the Llama book and I can't seem to figure out how to print to a 
|> specific line in the file.  I know about the "$." variable that holds the 
|> current input line number and that "$_" contains the input line contents,
|> but how do I get "print" to print $string to OUTPUTFILE at "$." ? 
|> 
|> I am sure this is probably a nobrainer and since I have no brain I should
|> be able to figure it out....but I can't.  Can anyone help?
|> 
|> By the way thank god for this list!
|> 
|> Thanks in advance,
|> Ernesto
|> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
|> % Ernesto Gonzalez                   %
|> % Computer Services Associate                %
|> % Massachusetts General Hospital     %       
|> % Dept of Molecular Biology          %
|> %                                            %
|> % Gonzalez@molbio.mgh.harvard.edu    %
|> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|> "RADICALISM = The conservatism of tomorrow injected into the affairs of
|>               today" - Ambrose Bierce    
-- 
Regards, Larry F. Allen-Tonar                   +1 619  655-8056
Software Designer                                lfat@sdd.hp.com

"While one person hesitates because he feels inferior, another
 is busy making mistakes and becoming superior." (Henry C. Link)

(Standard disclaimer:  My opinions              are my opinions, 
                                      are subject to change and
                         are perhaps 1/90000 likely to be HP's.)