fx3000 has asked for the wisdom of the Perl Monks concerning the following question:
Hello I'm a Perl Baby and I'm trying to use a srcipt in order to make substitutions in a file File.txt picking up from an other file Address.txt. I found a rellay nice perl script and it work, but not enough for my specific situation Here is the code:
#!/usr/bin/perl use warnings; use strict; open( my $out_fh, ">", "output.txt" ) || die "Can't open the output fi +le for wri ting: $!"; open( my $address_fh, "<", "Address.txt" ) || die "Can't open the addr +ess file: $!"; my %lookup = map { chomp; split( /,/, $_, 2 ) } <$address_fh>; open( my $file_fh, "<", "File.txt" ) || die "Can't open the file.txt f +ile: $!"; while (<$file_fh>) { my @line = split; for my $char ( @line ) { ( exists $lookup{$char} ) ? print $out_fh " $lookup{$char} " : + print $ou t_fh " $char "; } print $out_fh "\n"; }
It works fine if in my File.txt words are separated with a space, but i need to make this working on files that use a | like separator, and even on xml files . Any ideas?. Cheers
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How to substitute a word with an other?
by Anonymous Monk on May 16, 2014 at 13:55 UTC | |
by fx3000 (Initiate) on May 16, 2014 at 15:02 UTC | |
by Anonymous Monk on May 16, 2014 at 15:27 UTC | |
by Anonymous Monk on May 17, 2014 at 18:13 UTC | |
by morgon (Priest) on May 17, 2014 at 18:31 UTC | |
|
Re: How to substitute a word with an other?
by Anonymous Monk on May 16, 2014 at 14:25 UTC | |
by fx3000 (Initiate) on May 16, 2014 at 15:30 UTC | |
by Anonymous Monk on May 16, 2014 at 15:42 UTC |