Not getting expected output for below input lines.
Basically what I am doing is I am extracting hex values and values inside curly braces.
The values inside curly braces should be appended with 0x0 (eg 0x01)
The value with uint16 should be splited for e.g(0x27,0x89)
The negative value -116 I want to take 8C
since its type is sint8 (for e.g -116--Hex is FFFFFF8C-->8C)
I am using map
function for doing this, but I am getting output as some unexpected value.
My code:
use strict;
use warnings;
my @data;
while (<DATA>)
{
my (@matches) = /(?|(0x[dA-F]+)|(?:{s*|s)(-?d+)(?!x))/g;
#print "@matches
";
push @data, ($1);
}
{
my $data = join ',', map "0x0$_", map { unpack '(A2)*' } @data;
print $data, "
";
}
__DATA__
meas_command PHY_MEAS_CONFIG { 0} meas_command
UE_position_meas_flag else { 0} UE_position_meas_flag
reporting_interval MCFE_L1C_RPTPERIOD { 1} reporting_interval
fieldIndicator tdd neighbor cell measurement indicator { 2} fieldIndicator
Reserved1 0x00 Uint8,unsigned char
my_info 0x2789 Uint16, unsigned short
filler1{3} { 0x00, 0x00, 0x00 } Uint8,unsigned char
rscp_tap -116 Sint8,signed char
rch_type PCH { 7} Uint8,unsigned char
last_report 0 zeroth bit
no_sync 0 oneth bit
Expected output:
0x00,0x00,0x01,0x02,0x00,0x27,0x89,0x00,0x00,0x00,0x8c,0x07,0x00,0x00
What I was getting is:
0x00,0x00,0x01,0x02,0x00x,0x000,0x00x,0x027,0x089,0x00x,0x000,0x0-1,0x016,0x07,0x00,0x00
Something wrong is going with map
function.
Please help me ?
See Question&Answers more detail:
os