#!/usr/bin/perl use strict; use warnings; if ( @ARGV != 1 ) { print "USAGE :: perl default_operating_condition_update.pl <>\n\n"; exit 1; } my $inputfile = $ARGV[ 0 ]; # input FILE mkdir 'finallib' unless -d 'finallib'; open my $INFILE, '<', $inputfile or die "Can not open '$inputfile' because: $!"; open my $OPFILE, '>', "finallib/$inputfile" or die "Can not open 'finallib/$inputfile' because: $!"; while ( my $iline = <$INFILE> ) { print $OPFILE $iline; if ( $iline =~ /^ ( \s* ) operating_conditions \s* \( \s* ( .* ) \s* \) \s* { \s* $/x ) { my ( $leading_space, $operating_cond ) = ( $1, $2 ); until ( $iline =~ /^ \s* } \s* $/x ) { $iline = <$INFILE>; print $OPFILE $iline; } print $OPFILE "${leading_space}default_operating_conditions : $operating_cond ;\n"; } }