Hi, sorry, I'll try to be more detailed: I have a file we can call it Input.txt like the following

Input.txt 2014-04-24 14:22:52|TESTER001||/dev/pts/5|322655663|TYXRRES|0 2014-04-24 14:22:52|TESTER003||/dev/pts/5|323231258|TRRRDER|0 2014-04-24 14:22:52|TESTER002||/dev/pts/5|323135368|RCVDDER|0

And I need to operate a secific substitutions using a "map" the script can found in Changes.txt

Changes.txt TESTER001,Frank_Sinatra TESTER002,Jhon_Belushi TESTER003,Homer_Simson

After the changes the output should look like this:

Output.txt (desired) 2014-04-24 14:22:52|Frank_Sinatra||/dev/pts/5|322655663|TYXRRES|0 2014-04-24 14:22:52|Homer_Simson||/dev/pts/5|323231258|TRRRDER|0 2014-04-24 14:22:52|Jhon_Belushi||/dev/pts/5|323135368|RCVDDER|0

but the real Output.txt is different from my idea:

real Output.txt 2014-04-24 14:22:52 Frank_Sinatra /dev/pts/5 322655663 TYXRRES 0 2014-04-24 14:22:52 Homer_Simson /dev/pts/5 323231258 TRRRDER 0 2014-04-24 14:22:52 Jhon_Belushi /dev/pts/5 323135368|RCVDDER|0

So what I got is the right substitution but even an extra substitution of the | with a white space..... Here hte code i use

#!/usr/bin/perl use warnings; use strict; open( my $out_fh, ">", "Output.txt" ) || die "Can't open the output fi +le for writing: $!"; open( my $address_fh, "<", "Changes.txt" ) || die "Can't open the Chan +ges file: $!"; my %lookup = map { chomp; split( /,/, $_, 2 ) } <$address_fh>; open( my $file_fh, "<", "Input.txt" ) || die "Can't open the Input.txt + file: $!"; while (<$file_fh>) {

I think my problem is in the following Line...

my @line = split( /\|/, $_,); for my $char ( @line ) { ( exists $lookup{$char} ) ? print $out_fh " $lookup{$char} " : + print $out_fh " $char "; } print $out_fh "\n"; }

Thank you


In reply to Re^4: How to substitute a word with an other? by Anonymous Monk
in thread How to substitute a word with an other? by fx3000

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.