in reply to Re^3: no reaction on string replace
in thread no reaction on string replace

Hi, I just tried out your tip an I thought I got it..but I guess that is not the case :-(. The Code is now:
#!/usr/bin/perl -w use strict; my $SCU= 'C:/Users/Desktop/a.txt'; open(FILE, "<$SCU") || die "File not found"; my @lines = <FILE>; close(FILE); #my $copy = $_; my @newlines; foreach(@lines) { push @newlines, s/<test>/xyz/rg for @lines; } open (FILE, ">", "$SCU") or die "Could not open file $SCU: $!"; print FILE @newlines; close(FILE);
It is still no working. Can you tell me what I messed up? Thank you!

Replies are listed 'Best First'.
Re^5: no reaction on string replace
by poj (Abbot) on Sep 11, 2013 at 20:14 UTC
    You don't need the foreach loop as you have for @lines.
    #!/usr/bin/perl -w use strict; my $SCU = 'C:/Users/Desktop/a.txt'; open (FILE, '<', $SCU) or die "$SCU File not found : $!"; my @lines = <FILE>; close (FILE); my @newlines; #foreach(@lines) { push @newlines, s/test/xyz/rg for @lines; #} open (FILE, '>', $SCU) or die "Could not open file $SCU: $!"; print FILE @newlines; close (FILE);
    poj
Re^5: no reaction on string replace
by Eily (Monsignor) on Sep 11, 2013 at 21:33 UTC

    With the mistake that poj told you about, not only should you have add the content of your file modified, but the new lines should be in your file several times. If it's not the problem you have, try to add a print @lines to check that your file is read correctly. And if it is try to print @newlines to see if its content is what you expect.