I have run into the following problem: If I concatenate the packed values of a list to
a string, when I use the unpack operation to put the values back into an array, the
last element is missing. I can only get around the problem by specifying the exact
number of elements to unpack. And if I don't have that available, I would have to do
two unpack operations, the first one to find out how many elements are in the array of
packed values, the second to get the last value. This seems rather a waste to me. Is
there any way to solve this problem. Your help would be greatly appreciated. Thanks
in advance.
The following program illustrates the problem I am having:
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
$TBLXCOL_FORMAT = 'I/a*';
$lines[0] = "CLASSCOUNT PSOPRDEFN 8 2 SMALLINT N";
$lines[1] = "OPERPSWD PSOPRDEFN 9 32 CHAR N";
$lines[2] = "ENCRYPTED PSOPRDEFN 10 2 SMALLINT N";
$lines[3] = "SYMBOLICID PSOPRDEFN 11 8 CHAR N";
for ($i=0;$i<4;$i++) {
($column, $table) = split / +/, $lines[$i];
if (!exists($tblxcol{uc($table)})) {
$tblxcol{uc($table)} = pack ($TBLXCOL_FORMAT, $column);
}
else {
$tblxcol{uc($table)} .= pack ($TBLXCOL_FORMAT, $column);
}
}
print "1st example\n";
@array = unpack $TBLXCOL_FORMAT x 500, $tblxcol{PSOPRDEFN};
printf ("Array size: %ld\n", $#array+1);
$i = 0;
foreach $item (@array) {
$i++;
print "$i $item\n";
}
print "\n2nd example\n";
@array = unpack $TBLXCOL_FORMAT x ($#array+1), $tblxcol{PSOPRDEFN};
$i = 0;
foreach $item (@array) {
$i++;
print "$i $item\n";
}
exit 0;