Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Openning and writing back to same file

Status
Not open for further replies.

Tve

Programmer
May 22, 2000
166
FR
I want to open a file, modify it and then write back to the same file. This does not work, but I do not know why. Does asnyone know?


# Read the file in grep
open (INFILE,"c:/TREEINFO.WC") or die "Error $f_file: $!";
@lines = <INFILE>;
close INFILE;
open (OUTFILE,&quot;>c:/TREEINFO.WC&quot;) or die &quot;Error $f_file: $!&quot;;


# Loop and print the subs value
foreach $line (@lines) {
$line =~ s! {2,}$!!;
print OUTFILE &quot;$line&quot;;
}
 
what is happening that it is not working? do you get an error or does the file just remain the same as it was before?

Regards,
Gerald
 
an obvious question probably, but what is this bit meant to do?

$line =~ s! {2,}$!!;

Mike
michael.j.lacey@ntlworld.com
 
I think that is trying to replace 2 spaces at the end of the string with null. The pattern matching will allow you to use delimiters other than '/' for the find and replace definitions.




keep the rudder amid ship and beware the odd typo
 
tve

try this then

$line =~ s/ $//;
Mike
michael.j.lacey@ntlworld.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top