ok sorry... must of missed that about the in place editor and is restrictions ! Please ignore that last part of my last email!
[EMAIL PROTECTED] (Peter Scott) Sent by: [EMAIL PROTECTED] (Peter Scott) 09/16/2004 06:14 PM Please respond to Peter To: [EMAIL PROTECTED] cc: Subject: Re: $ ^ I in place editor In article <[EMAIL PROTECTED]>, [EMAIL PROTECTED] writes: >its not that I do not understand its purpose, but maybe how to use it??? I >am curious b/c this has worked for me before in other programs. I will >send this whole code. Posting hundreds of lines of code that have nothing to do with what you're trying to understand will only make it harder to understand it. And the full code doesn't match the sample code you posted below in a crucial respect: You don't even set @ARGV at all in the full code. And still don't use the diamond operator. Take a look at what I wrote before: -- Nowhere do you use the contents of @ARGV. In-place edit only works when you use the diamond operator (<>) for I/O, and you haven't. So, having defined $^I and set @ARGV, you then need a loop: while (<>) { # Do something with $_ # print something to default filehandle } Whatever you print to the default filehandle inside that loop will go to the new file. -- Here's a sample program, run it and see what it does, and experiment with it if need be. Then you will understand how to use $^I. #!/usr/local/bin/perl use strict; use warnings; my $file = "INSERT NAME OF FILE TO MODIFY HERE"; print "Starting in-place edit of $file\n"; ($^I, @ARGV) = (".bak", $file); while (<>) { s/e/x/g; print; } print "Done in-place edit, now look at $file\n"; Look also at "perldoc perlrun" under "-i". >In article ><[EMAIL PROTECTED]>, > [EMAIL PROTECTED] writes: >>In my code I am not understanding why my in place edit does not work? >Here >>is my code: >> >>use strict; >>use diagnostics; >>use warnings; > >Good! > >>my stps="/usr/local/log/scratchtps"; >> >> open (TP, ">$stps") || die "could not open file:$!"; >> open (TP2, ">$irmt ") || die "could not open file:$!"; >> open (D, "$logf") || die "could not open file:$!"; >> ($^I, @ARGV) = ('.bak', $scratchtps); > >I think you copied this line from somewhere without understanding it. [snip] -- Peter Scott http://www.perldebugged.com/ *** NEW *** http://www.perlmedic.com/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>