I've got a little program that opens a file to read then writes it to a NEW file. I'll like to search out some keywords and replace them in the NEW file.

I am having trouble figuring out how to do a substitute string and then continue to write out the rest of the content with NEW edit in the NEW file.

#!usr/bin/perl # program takes a base part and changes some fields to show new part # use strict; #use warning; #use 5.280; use Data::Dumper; use Fcntl qw(:flock SEEK_END); use Cwd 'abs_path'; # Info from Base Part Job report my $base_part_test = '5237all5x_a1_rpt.txt'; my $base_part_file = '5237all5x'; my $base_part_file_uc = uc $base_part_file; my $base_part_rev = 'a1'; my $base_part_rev_lc = lc $base_part_rev; my $base_part_Customer = 'SA'; my $base_path = '/Product/SA_customer_product/'.$base_part_Customer.'/ +'.$base_part_file_uc.'/'.$base_part_file_uc.'_rev_'.$base_part_rev_lc +.'/RetBuildReport'; my $Real_base_part_file = $base_path.'/'.$base_part_file.'_'.$base_par +t_rev.'_rpt.txt'; #check if the Report file exists in the directory then do the substitu +tion of builder. if ( -f $Real_base_part_file) { # Info to New Buld Report my $New_part_report = 'NEW_PART_REPORT.txt'; # Test what's inside the vars print Dumper ( $base_part_file, $base_part_rev , $base_path, $Real_bas +e_part_file ); # Creating a file system "touch $New_part_report"; my $New_Part_Date = system "date"; open my $base_fh , '+<', $base_part_test or die; open my $New_fh ,'>', $New_part_report or die; while(my $line = <$base_fh>) { if ($line eq "Builder : Xi Wong"){ print " found original builder : "; Want to substitute builder Xi Wong to Lucca P. but not + sure how??? # then continue to write the rest of report print $New_fh $line; } } close($base_fh); close($New_fh); }

These are the substitution I am trying to change on the fly. If you can give me an idea of doing one substitution then I can do the rest of them. I just need some help to go about it

Original base part to start. This File gets read. In his case, Builder is Xi Wong but can be others

--------------------------------------- Basic Information: --------------------------------------- Build Report Rev: 02 + Builder: Xi Wong Part Name: MG5237ALL5X + Customer Name: SI Route: S5H2-12A

This shows only the builder substitution from old to new. In this case, it is Lucca P. but can be others

--------------------------------------- Basic Information: --------------------------------------- Build Report Rev: 01 + Builder: Lucca P. Part Name: MG5415DP + Customer Name: SA Route: S5H2-12A

In reply to Edit a New file in place after reading it in by perlynewby

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.