in reply to problem with string substitution output
This means that the output file is overwritten with what you print in the last iteration.
So you have to change the nesting of the loops. You can get around using the loop over the words altogether with a little trick:
my $all_words_regex = join '|', keys %lijst; for my $file (@listfiles) { open my $in, '<', $file or die "Can't open file '$file' for reading +: $!"; open my $out, '>', "$file.out" or die "Can't open file '$file.out' +for writing: $!"; while (<$in>){ if (m/^($all_words_regex)/){ my $first_word = $1; s/$first_word/$echo/g; s/$echo/$first_word/; } print $out $_; } }
BTW all of your programs should start like this:
use strict; use warnings;
And you should declare all your variables with either my (most of the time) or our.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: problem with string substitution output
by Anonymous Monk on May 23, 2008 at 16:20 UTC | |
by moritz (Cardinal) on May 23, 2008 at 16:26 UTC | |
by Anonymous Monk on May 23, 2008 at 16:39 UTC | |
by moritz (Cardinal) on May 23, 2008 at 16:46 UTC |