A & B & D - see perlretut. Expand the addr regex to include more than just digits
if (/($re).*addr = ([.\da-fA-F:]+)/){
and the other to include all character up to a comma
while (/($re)[ =]*([^,]+)/g){
C & E- Standardize your keywords to a single space private_uid =
and process the input lines to collapse multiple spaces down to one
s/ +/ /g; # remove multiple spaces
I suspect as a result of expanding the value regex you will
capture things you then want to exclude. I have added a basic cleanup sub
for you to expand as required. Full changes are
for my $file (@files){
my $line_no = 0;
print "Reading $file\n";
open my $fh, '<', $file or die $!;
while (<$fh>){
chomp;
++$line_no;
s/ +/ /g; # remove multiple spaces
# special pcscf_v4 extract addr
if (/($re).*addr = ([.\da-fA-F:]+)/){
my $msg = update_sheet($1,$2,$_);
print "Line $line_no $msg special\n";
next;
}
# match more than 1 per line e.g. usim and isim
while (/($re)[ =]*([^,]+)/g){
my $msg = update_sheet($1,$2,$_);
print "Line $line_no $msg\n";
}
}
close $fh;
}
# update sheet
sub update_sheet {
my ($kw,$value,$comment) = @_;
my $clean = cleanup($kw,$value);
my ($sht,$r,$c) = @{$kwhashref->{$kw}}[0..2];
my $sel = $Book->Worksheets($sht)->Cells($r,$c+1);
$sel->Insert({ Shift => -4161}); # xlToRight
$sel->{Value} = $clean;
$sel->AddComment( { Text=> $comment } );
$sel->Comment->Shape->TextFrame->{ AutoSize } = 1;
$kwhashref->{$kw}[3] = $value; # for debugging
$kwhashref->{$kw}[4] = $clean; # for debugging
return "kw=[$kw] value=[$value] clean=[$clean]";
}
# remove unwanted chars from value
sub cleanup {
my ($kw,$value) = @_;
# generic cleansing
$value =~ s/[\[\]]//g; # remove all [] brackets
$value =~ s/^\s+//g; # remove leading whitespace
$value =~ s/\s+$//g; # remove trailing whitespace
# specific cleansing
#if ($kw =~ //){
# $value =~ s///g
#}
return $value;
}
poj