in reply to problem with string substitution output
There are some unclear parts in your code, we don't know how your data looks like (so there may be any kind of problem).
You should alwyas open one file after another and do all the work in one file at once. I reorganized your code (out of the blue, don't know your data) - maybe thats a new starting point.
... my $echo = 'ECHO'; my ($dffname, $listname) = @ARGV; my $fh; # read key/val lists open $fh, '<', $dffname or die "$dffname $!"; my %lijst = map { chomp; (split /\t|\s{2,}/)[1,0] } <$fh>; close $fh; # readfile list open $fh, '<', $listname or die "$listname $!"; my @listfiles = <$fh>; chomp @listfiles; close $fh; for my $file (@listfiles) { # read original file open $fh, '<', $file or die "$file $!"; local $/; my $content = <$fh>; close $fh; # modify content while( my ($key, $val) = each %lijst ) { next unless $val == 1; $content =~ s/^$key$/$echo/gms; $content =~ s/^$key$/$echo/; # re-subsitute first (?) } # write modified file open $fh, '>', "$file.out" or die "$file.out $!"; print $fh $content } ...
Regards
mwa
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: problem with string substitution output
by Anonymous Monk on May 23, 2008 at 16:33 UTC | |
by Anonymous Monk on May 23, 2008 at 19:43 UTC | |
by Anonymous Monk on May 23, 2008 at 20:14 UTC |
In Section
Seekers of Perl Wisdom