First uncomment the use warning and change 'warning' to 'warnings'. Your intent to use strictures (strict and warnings) is good, but ignoring errors is really bad.
Now consider the following self contained example script:
use strict; use warnings; my $template = <<FILE; --------------------------------------- Basic Information: --------------------------------------- Build Report Rev: 02 Builder: Xi Wong Part Name: MG5237ALL5X Customer Name: SI Route: S5H2-12A FILE my $outText; my %subs = ( 'Build Report Rev' => '01', 'Builder' => 'Lucca P.', 'Part Name' => 'MG5415DP', 'Customer Name' => 'SA', 'Route' => 'S5H2-12A' ); # Info to New Buld Report open my $base_fh, '<', \$template; open my $New_fh, '>', \$outText; while (my $line = <$base_fh>) { if ($line =~ /^([^:]+):(\s+)/ && exists $subs{$1}) { $line = "$1:$2$subs{$1}\n"; } print $New_fh $line; } close $base_fh; close $New_fh; print $outText;
Prints:
--------------------------------------- Basic Information: --------------------------------------- Build Report Rev: 01 Builder: Lucca P. Part Name: MG5415DP Customer Name: SA Route: S5H2-12A
which I think does what you want. Notice the hash used to store the substitution values. In a real life example that could be populated from a database or from a file containing the required edits. Although, in real life it feels like this whole exercise should be done using a database. You may be interested in Databases made easy for an introduction to using databases.
In reply to Re: Edit a New file in place after reading it in
by GrandFather
in thread Edit a New file in place after reading it in
by perlynewby
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |