I need to read in the string from input file and reform it by cut each segment and check the last segement lenght. If the last segment length is not as expected (see below segment file or table. It is predefined), then pad enough space.
if you see the sample old and new strings I incluced, basically go through the entire string segment by segment (segment id and length are defined at the table at the end of post). Only if the last segment length is not as expected, then pad spaces, else the old string and new string should be the same,except that new string gets padded with && at the end of string.
In plain program language:
cut the first two byte from the input string as segment id, and lookup segment id table with segment id to get segment length. The cut the inputstring with that length and save the new cutted string. Repeat the same logic till the end of inputstring. If the length of last piece of string is the lenghth from segment lookup, then append space.
See the example, last segment BP is only 5 bytes long. But segment length for BP is 20 (see segment table), so the new string length for the BP will be 5+15 spaces.
It works perfect. Do you know how to insert control character with VI editor? Also how can I send the output to a file? I tried and could not make it work
my $str='FU22222222CA6666666666AKxvbFMddreeadBP99';
while(<DATA>){
my @tmp = split;
$hash{$tmp[0]}=$tmp[1]-length($tmp[0]);
$reg2=$reg2.'|'.$tmp[0];
}
$reg2=~s/^\|//;
my @tmp =split(/(?=(?:$reg2))/,$str);
map { s/($reg2)(.*)/$1.$2.' 'x($hash{$1}-length($2))/e} @tmp;
print join "", @tmp;
print "<---\n";
__DATA__
FU 10
CA 12
AK 10
FM 9
BP 10
Thanks Summer Cherry for providing the perl script. As I do not have any perl experience, would you mind send me the complete script. So I can execute. Also can you please replace the string with file. the actual data I need to process is in a file.