in reply to Modify a line following a target line?
my @records = split(/^(?=I)/m, $file);
The just extract the REFDES and modify the PKG_TYPE
my %pkg_lkup ( ... => ..., ... => ..., ... => ..., ); for my $rec (@records) { if ( my ($refdes) = $rec =~ /REFDES=(.*)/ ) { if (exists($pkg_lkup{$refdes})) { $rec =~ s/PKG_TYPE=.*/PKG_TYPE=$pkg_lkup{$refdes}/; } } print($rec); }
In Perl 5.10, the substitution can be written more efficiently as
$rec =~ s/PKG_TYPE=\K.*/$pkg_lkup{$refdes}/;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Modify a line following a target line?
by djincnj (Initiate) on Jan 06, 2009 at 17:09 UTC | |
by gwadej (Chaplain) on Jan 06, 2009 at 18:18 UTC |