RE: over-writing a file
From: "Scott Lutz" <[EMAIL PROTECTED]> > Re : perldoc -q "I just want to increment the number in the file" > > How does one find (out about) these obscure perldoc functions? > My word! The of-so-usual -h option gives you information on perldoc's ussage: perldoc [options] PageName|ModuleName|ProgramName... perldoc [options] -f BuiltinFunction perldoc [options] -q FAQRegex FAQRegex is a regex. Will search perlfaq[1-9] for and extract any questions that match. So you might try just perldoc -q file if that's too long try something more. Say perldoc -q increment.*file And you are there. Jenda === [EMAIL PROTECTED] == http://Jenda.Krynicky.cz == There is a reason for living. There must be. I've seen it somewhere. It's just that in the mess on my table ... and in my brain. I can't find it. --- me -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: over-writing a file
Hi John, Just brilliant, thanks. Ken > -Original Message- > From: John W. Krahn [mailto:[EMAIL PROTECTED]] > Sent: Saturday, March 09, 2002 12:08 AM > To: [EMAIL PROTECTED] > Subject: Re: over-writing a file > > > Ken Cole wrote: > > > > Hi, > > Hello, > > > I have a file with say the value "02" in it. > > > > I can open the file, lock the file, read the value, > increment the value > > and do a write but the write always appends and never > over-writes the > > exisitng value. I of course then unlock and close. > > > > I do a seek before the write to the beginning of the file, > even checked > > with "tell" and it returns "0",but the following print or syswrite > > always appends. > > > > Why? How do I over-write? > > > perldoc -q "I just want to increment the number in the file" > > > John > -- > use Perl; > program > fulfillment > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: over-writing a file
Re : perldoc -q "I just want to increment the number in the file" How does one find (out about) these obscure perldoc functions? My word! Scott Lutz Pacific Online Support Phone: 604.638.6010 Fax: 604.638.6020 Toll Free: 1.877.503.9870 http://www.paconline.net -Original Message- From: John W. Krahn [mailto:[EMAIL PROTECTED]] Sent: March 8, 2002 6:08 AM To: [EMAIL PROTECTED] Subject: Re: over-writing a file Ken Cole wrote: > > Hi, Hello, > I have a file with say the value "02" in it. > > I can open the file, lock the file, read the value, increment the value > and do a write but the write always appends and never over-writes the > exisitng value. I of course then unlock and close. > > I do a seek before the write to the beginning of the file, even checked > with "tell" and it returns "0",but the following print or syswrite > always appends. > > Why? How do I over-write? perldoc -q "I just want to increment the number in the file" John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: over-writing a file
Anette Seiler wrote: > > Hi Ken, > > I encountered exactly the same problem today: How to read a file > AND change something in it? I was not able to do both of them at > the same time. > > I am sure there is a more correct way to do it, but my solution (in > the spirit of TIMTOWTDI) was to write to a temporary file and then > rename the temporary file to the name of the original file, like: > > open FILE, "original.txt" or die "Cannot open file original.txt ($!)\n"; > open TEMP, ">temp.txt" or die "Cannot open file temp.txt ($!)\n"; > > foreach my $line (){ > $line =~ s/find/replace/gi ; > print TEMP "$line\n"; > } > > close FILE; > close TEMP; > > rename "temp.txt", "original.txt; > do it with perl -pi -e 's/find/replace/gi;' original.txt note that you'll lose the file if you do a mistake, perl -pibak -e 's/find/replace/gi;' original.txt will create a backup file look at 'perldoc perlrun' /jon > It works, but as I say, I am sure, this is not the best way to do it. > Therefore, I am just as curious as you, what the experts will tell us. > > By the way, dear experts, I am really grateful for the time and effort > you spend helping us newbies. I learned a lot since I subscribed to > the list. Thank you! > > Greetings from a sunny Cologne, Germany > > Anette > > > Hi, > > > > I have a file with say the value "02" in it. > > > > I can open the file, lock the file, read the value, increment the > > value and do a write but the write always appends and never > > over-writes the exisitng value. I of course then unlock and close. > > > > I do a seek before the write to the beginning of the file, even > > checked with "tell" and it returns "0",but the following print or > > syswrite always appends. > > > > Why? How do I over-write? > > > > Thanks > > > > Ken > > > > -- > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > For additional commands, e-mail: [EMAIL PROTECTED] > > > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: over-writing a file
Hi Ken, I encountered exactly the same problem today: How to read a file AND change something in it? I was not able to do both of them at the same time. I am sure there is a more correct way to do it, but my solution (in the spirit of TIMTOWTDI) was to write to a temporary file and then rename the temporary file to the name of the original file, like: open FILE, "original.txt" or die "Cannot open file original.txt ($!)\n"; open TEMP, ">temp.txt" or die "Cannot open file temp.txt ($!)\n"; foreach my $line (){ $line =~ s/find/replace/gi ; print TEMP "$line\n"; } close FILE; close TEMP; rename "temp.txt", "original.txt; It works, but as I say, I am sure, this is not the best way to do it. Therefore, I am just as curious as you, what the experts will tell us. By the way, dear experts, I am really grateful for the time and effort you spend helping us newbies. I learned a lot since I subscribed to the list. Thank you! Greetings from a sunny Cologne, Germany Anette > Hi, > > I have a file with say the value "02" in it. > > I can open the file, lock the file, read the value, increment the > value and do a write but the write always appends and never > over-writes the exisitng value. I of course then unlock and close. > > I do a seek before the write to the beginning of the file, even > checked with "tell" and it returns "0",but the following print or > syswrite always appends. > > Why? How do I over-write? > > Thanks > > Ken > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: over-writing a file
Ken Cole wrote: > > Hi, Hello, > I have a file with say the value "02" in it. > > I can open the file, lock the file, read the value, increment the value > and do a write but the write always appends and never over-writes the > exisitng value. I of course then unlock and close. > > I do a seek before the write to the beginning of the file, even checked > with "tell" and it returns "0",but the following print or syswrite > always appends. > > Why? How do I over-write? perldoc -q "I just want to increment the number in the file" John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
over-writing a file
Hi, I have a file with say the value "02" in it. I can open the file, lock the file, read the value, increment the value and do a write but the write always appends and never over-writes the exisitng value. I of course then unlock and close. I do a seek before the write to the beginning of the file, even checked with "tell" and it returns "0",but the following print or syswrite always appends. Why? How do I over-write? Thanks Ken -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]