Not getting numbers to print out from report

M

mike.wilson8

I'm substr from a sas report and loading numbers into a hash
table..code below

$MsgRate = substr($thisline,59,5);
$MsgRate =~ s/\s+$//;
$MsgRate =~ s/^\s+//;


if (! exists
$crsCode{$crs}{$source}{$pcc}{$TransactionType}{$MsgRate})
{

$crsCode{$crs}{$source}{$pcc}{$TransactionType}{'MsgRate'} = $MsgRate;

print ("hash read,
$crsCode{$crs}{$source}{$pcc}{$TransactionType}{'MsgRate'}\n")
}

** The last line of code above is a print test statement just to make
sure I was loading the numbers okay, and I am.

Last step--I'm opening and running a report (code below), but instead
of seeing numbers from $MsgRate which I validated above, the report is
just spitting out the word MsgRate. Any ideas?

open(RPT,">$rptname") || die "Cannot open $rptname\n";


for $crs ( sort keys%crsCode)
{

for $source ( sort keys%{$crsCode{$crs}})
{
for $pcc ( sort keys%{$crsCode{$crs}{$source}})
{
for $TransactionType ( sort
keys%{$crsCode{$crs}{$source}{$pcc}})
{

for $MsgRate ( sort
keys%{$crsCode{$crs}{$source}{$pcc}{$TransactionType}})
{


print(RPT
"${greg}\t${hour}\t${crs}\t${source}\t${pcc}\t${TransactionType}\t${MsgRate}\n");




}


}


}


}

}
 
P

Paul Lalli

I'm substr from a sas report and loading numbers into a hash
table..code below

$MsgRate = substr($thisline,59,5);
$MsgRate =~ s/\s+$//;
$MsgRate =~ s/^\s+//;


if (! exists
$crsCode{$crs}{$source}{$pcc}{$TransactionType}{$MsgRate})

Here you're checking to see if the key $MsgRate (ie, a variable)
exists.
{

$crsCode{$crs}{$source}{$pcc}{$TransactionType}{'MsgRate'} = $MsgRate;

Here, you're assigning the variable $MsgRate to be the value of the key
'MsgRate' (ie, a string).

The two keys are completely un-related. It's time for you to re-think
what it is you are actually trying to do.
print ("hash read,
$crsCode{$crs}{$source}{$pcc}{$TransactionType}{'MsgRate'}\n")
}

** The last line of code above is a print test statement just to make
sure I was loading the numbers okay, and I am.

Yes, you are setting the value at the key 'MsgRate' to the variable
$MsgRate, so the variable $MsgRate prints out.
Last step--I'm opening and running a report (code below), but instead
of seeing numbers from $MsgRate which I validated above, the report is
just spitting out the word MsgRate. Any ideas?

open(RPT,">$rptname") || die "Cannot open $rptname\n";


for $crs ( sort keys%crsCode)
{

for $source ( sort keys%{$crsCode{$crs}})
{
for $pcc ( sort keys%{$crsCode{$crs}{$source}})
{
for $TransactionType ( sort
keys%{$crsCode{$crs}{$source}{$pcc}})
{

for $MsgRate ( sort
keys%{$crsCode{$crs}{$source}{$pcc}{$TransactionType}})
{

Here you're asigning the variable $MsgRate to each key from the hash.
As shown above, each key is simply the string 'MsgRate'.
print(RPT
"${greg}\t${hour}\t${crs}\t${source}\t${pcc}\t${TransactionType}\t${MsgRate}\n");

And here, you print out that variable, which contains the string.


I *think* what you wanted to do was assign $MsgRate to be the value of
the key 'MsgRate' above (ie, fix your initial exists() line), and then
have one less nested loop here at the bottom:
for my $TransactionType ( sort keys%{$crsCode{$crs}{$source}{$pcc}}) {
print join ("\t", $greg, $hour, $crs, $source, $pcc,
$TransactionType,
$crsCode{$crs}{$source}{$pcc}{$TransactionType}{MsgRate});
print "\n";
}


Of course, I could be wrong in my assumptions about your desires....

Paul Lalli
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,184
Messages
2,570,978
Members
47,561
Latest member
gjsign

Latest Threads

Top