in reply to Re^13: How to read the value of a variable (read from a Excel file converted Into text file) and put then back into Excel column
in thread How to read the value of a variable (read from a Excel file converted Into text file) and put then back into Excel column
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 spacesI 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
pojfor 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; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^15: How to read the value of a variable (read from a Excel file converted Into text file) and put then back into Excel column
by rockyurock (Acolyte) on Feb 25, 2017 at 16:41 UTC | |
by rockyurock (Acolyte) on Feb 25, 2017 at 17:16 UTC | |
by poj (Abbot) on Feb 26, 2017 at 17:28 UTC | |
by rockyurock (Acolyte) on Feb 27, 2017 at 07:35 UTC | |
by rockyurock (Acolyte) on Feb 27, 2017 at 07:57 UTC | |
|