rightfield has asked for the wisdom of the Perl Monks concerning the following question:
Need I say, it looks right to me... I've looked at many examples. The subroutine originally just wrote the file. I am testing a way to change a line that starts with 'JOB=' to "RMT=filename. Thanks for your help and warm regards.readline() on closed filehandle T at blah. See comment below for line. + print() on closed filehandle T at blah. See comment below for line.
sub t_write { my($file, $aOrder) = @_; my($trace) = $aOrder->{trace_file_data}; my $counter = 0; if (!defined($trace) || length($trace) == 0) { print "No trace file.\n"; return; } open(F, "> $file\0") or die "Can't create trace-file $file ($!)\n" +; print F $trace; close(F); # new start testing >>>>>> open (T, "+<$trace"); my @array = <T>; #this has the readline error foreach my $line (@array) { if ($line =~ /^JOB=/) { $array[$counter] = "RMT=$file\n"; } $counter++; } print T @array; #this has the print() error close(T); # end testing <<<<< #make a comment that this was done print "Trace file: $file\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Change a line in a file
by betterworld (Curate) on Aug 18, 2008 at 02:36 UTC | |
|
Re: Change a line in a file
by GrandFather (Saint) on Aug 18, 2008 at 02:38 UTC | |
|
Re: Change a line in a file
by BrowserUk (Patriarch) on Aug 18, 2008 at 02:48 UTC | |
|
Re: Change a line in a file
by CountZero (Bishop) on Aug 18, 2008 at 05:48 UTC | |
by rightfield (Sexton) on Aug 23, 2008 at 23:23 UTC | |
|
Re: Change a line in a file
by netbpa (Initiate) on Aug 18, 2008 at 23:40 UTC |