I have a script that reads in a spool report and extracts fields from each line. I have one field that my debugging shows is being extracted correctly but when I output it to another file using the printf function its value gets changed. I was writing this as a signed decimal field. However, if I change it to a string field, the correct value is maintained.
The incoming/extracted value of field $GLO is 22,902,247.70 and as my code snippets below show, I am stripping out editing characters and white space. Then when it gets written to the output file its value becomes -2004720226 but I cannot determine why. If I debug the content of the field immediately prior to the printf statement the content is correct.
I know that I must be missing something obvious but I cannot seem to locate the true reason. Hopefully some of you perl guru's can peruse the code below and advise what must be incorrect. All comments appreciated. Thanks
# Define Scalars
my @GLC=0; # GL Number Control Field
my $GLCW=""; # GL Control Work Field
my $GLCTG=""; # GL Category Code
my $GLN=""; # GL Account Number
my $GLD=""; # GL Account Description
my $GLT=""; # GL Account Type
my $GLO=0; # GL OAccount Opening Balance
# Extract Fields from this record
($GLN,$GLD,$GLT,$GLO)=unpack("A15xA45x2Ax4A16",$_);
# Assure Opening Balance is NOT null
if (!$GLO) {
$GLO=0;
}
# Strip out editing characters
$GLO=~s/[,.]//g;
$GLO=~s/^\s+//;
# Output Fixed Format GL Account Record
printf OFH ("%12s%s%2s%15s%-45s%s%13s\n", $GLCW,$FT,$GLCTG,$GLN,$GLD,$GLT,$GLO);
The incoming/extracted value of field $GLO is 22,902,247.70 and as my code snippets below show, I am stripping out editing characters and white space. Then when it gets written to the output file its value becomes -2004720226 but I cannot determine why. If I debug the content of the field immediately prior to the printf statement the content is correct.
I know that I must be missing something obvious but I cannot seem to locate the true reason. Hopefully some of you perl guru's can peruse the code below and advise what must be incorrect. All comments appreciated. Thanks
# Define Scalars
my @GLC=0; # GL Number Control Field
my $GLCW=""; # GL Control Work Field
my $GLCTG=""; # GL Category Code
my $GLN=""; # GL Account Number
my $GLD=""; # GL Account Description
my $GLT=""; # GL Account Type
my $GLO=0; # GL OAccount Opening Balance
# Extract Fields from this record
($GLN,$GLD,$GLT,$GLO)=unpack("A15xA45x2Ax4A16",$_);
# Assure Opening Balance is NOT null
if (!$GLO) {
$GLO=0;
}
# Strip out editing characters
$GLO=~s/[,.]//g;
$GLO=~s/^\s+//;
# Output Fixed Format GL Account Record
printf OFH ("%12s%s%2s%15s%-45s%s%13s\n", $GLCW,$FT,$GLCTG,$GLN,$GLD,$GLT,$GLO);