Hi guys
I have many kinds of different reports where the data is located at the same position as the headers.
For example, as you can see here WBTS-1695 is just under header NE-ID, L6070407474 is just under "Target Id" column and so on.
I want to make a generic sub routine to get data based on "column positions", using regex on the headers as reference and substr function.
Following code works fine for example with "HEADERFIVE", but not with "HEADER ONE"
I believe that still I have to calculate the spaces between the headers. For example between headers "NE-ID" and "Target Id".
Suggestions are welcome, and as I said before there are many reports with different info, but always data and headers are aligned
from left to right.
dmazzini
GSM/UMTS System and Telecomm Consultant
I have many kinds of different reports where the data is located at the same position as the headers.
For example, as you can see here WBTS-1695 is just under header NE-ID, L6070407474 is just under "Target Id" column and so on.
Code:
NE-ID Target Id In Topology Feature Name
------------------------------------------------------------------------------
WBTS-1695 L6070407474 Yes IMA (FTM)
WBTS-1695 L6070407474 No Antenna Line Supervision
WBTS-1695 L6070407474 Yes BTS channel capacity
I want to make a generic sub routine to get data based on "column positions", using regex on the headers as reference and substr function.
Following code works fine for example with "HEADERFIVE", but not with "HEADER ONE"
Code:
#!/usr/bin/perl
my $headers= qq(HEADER ONE HEADERTWO HEADER3 HEADER FOUR HEADERFIVE);
my $data= qq( data1 belong to data2 data3 my data 4 datafive);
if ($headers=~ /(HEADER ONE)/){
print "Headers:$headers\n";
my $length_headers=length($headers);
print "Length_Headers =>$length_headers\n";
print "Matched:$1\n";
my $length_matched=length($1);
print "Length_Matched =>$length_matched\n";
print "Before_Matched =>$`\n";
my $length_before_matched=length($`);
print "Length_Before_Matched =>$length_before_matched\n";
print "After_Matched =>$'\n";
my $length_after_matched=length($');
print "Length_After_Matched =>$length_after_matched\n";
$VALUETOGET = substr( $data,$length_before_matched,$length_matched);
print "VALUE:$VALUETOGET\n"; # this gives me: " to data2" instead of "belong to data2"
}
I believe that still I have to calculate the spaces between the headers. For example between headers "NE-ID" and "Target Id".
Suggestions are welcome, and as I said before there are many reports with different info, but always data and headers are aligned
from left to right.
dmazzini
GSM/UMTS System and Telecomm Consultant