Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
We are passing an array reference of results sets from the main program to this function which prints the contents of the result sets to the flat file. In this case,not able to print the contents. here is the code snippet of the function
The array reference is in argument 6
sub pkoutFile { my(@args)= @_; my($val, $i,$j,$k,$k1,$ln,@ff,@ss,$delim1, $delim2, @paramVals ); # 0 1 2 3 4 5 + 6 my($outFH, $delims, $branchID, $sourceSystem, $valDateY4MD, $rate +Type, $rowsHdl ) = @args[0..6]; $colNamesHdl = $args[7] if ($#args >= 7); $delims =~ s/(^[\n\r\s\t]+)|([\n\r\s\t]+$)//g; $branchID =~ s/(^[\n\r\s\t]+)|([\n\r\s\t]+$)//g; $valDateY4MD =~ s/(^[\n\r\s\t]+)|([\n\r\s\t]+$)//g; $sourceSystem =~ s/(^[\n\r\s\t]+)|([\n\r\s\t]+$)//g; $rateType =~ s/(^[\n\r\s\t]+)|([\n\r\s\t]+$)//g; $delim1 = substr($delims,0,1); $delim2 = substr($delims,1,2); printf($outFH "H\^%s\^%s\^%s\^%08d^\n", $delims, $branchID, $sourceS +ystem, $valDateY4MD); # determine the field names if ($colNamesHdl) { @ff=(); for ($i=0; $i <= $#$colNamesHdl; $i++) { push(@ff, $$colNamesHdl[$i]); } } else { $k = $$rowsHdl[0]; @ff = keys(%$k); } $j = $#$rowsHdl; for ($i=0; $i <= $j; $i++) { @paramVals = (); foreach $k (@ff) { $k1= $k; $k1 =~ s/(^[\n\r\s\t]+)|([\n\r\s\t]+$)//g; $val = $$rowsHdl[$i]->{$k}; # add logic here to make sure that the delims are NOT in the tex +t push(@paramVals, $k . $delim2 . $val); } print($outFH ('C^D^' . $rateType . '^' . join($delim1, @paramVals +) . "^\n")); } print($outFH "T^${branchID}^${sourceSystem}^\n"); }
Need your help to print the contents of the array reference to the file
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Unable to print the contents of an array reference passed from the main pgm to the flat file
by roboticus (Chancellor) on Aug 23, 2010 at 14:07 UTC | |
Re: Unable to print the contents of an array reference passed from the main pgm to the flat file
by moritz (Cardinal) on Aug 23, 2010 at 14:10 UTC | |
Re: Unable to print the contents of an array reference passed from the main pgm to the flat file
by wfsp (Abbot) on Aug 23, 2010 at 14:09 UTC | |
Re: Unable to print the contents of an array reference passed from the main pgm to the flat file
by murugu (Curate) on Aug 23, 2010 at 14:13 UTC | |
by Anonymous Monk on Aug 23, 2010 at 14:36 UTC | |
by Marshall (Canon) on Aug 24, 2010 at 06:07 UTC |