in reply to Re: problem with string substitution output
in thread problem with string substitution output
because otherwise it gave me this error: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: $!";
Unsuccessful open on filename containing newline at test.pl line 18
But this gives me the exact same result as it did without your alterations. Or am I doing something wrong?use strict; use warnings; my $echo="ECHO"; my $value=undef; my $key=undef; my %lijst=(); open (DFFILE,$ARGV[0]) || die "DF-file not found\n"; open (LIST,$ARGV[1]) || die "List not found\n"; while (<DFFILE>) { ($value, $key) = split(/\t/, $_); $lijst{$key} = $value; } my @listfiles = <LIST>; 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 $_; } } close(DFFILE);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: problem with string substitution output
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 |