in reply to appending to a particular line in a file
Doing a substitution on the whole string is a bit odd anyway. And you don't need the /g. How about (staying with the level of verbose clarity you are using):
Update: A more streamlined version might be:foreach $txtfile (glob("*.TXT")) { print $txtfile; print "\n"; open FILE, "$txtfile"; open NEWFILE, ">$txtfile.tmp"; while (<FILE>){ chomp $_; if ($. == 1){ $_ .= " 1.0"; # i.e. $_ = $_ . " 1.0"; } print NEWFILE $_, "\n"; } close FILE; close NEWFILE; }
foreach $txtfile (glob("*.TXT")) { print $txtfile; print "\n"; open FILE, "$txtfile"; open NEWFILE, ">$txtfile.tmp"; while (<FILE>){ $_ =~ s/\n/ 1.0\n/ if $. = 1; print NEWFILE $_; } close FILE; close NEWFILE; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: appending to a particular line in a file
by mndoci (Scribe) on Aug 03, 2001 at 02:37 UTC |