Hi guys. Just playing with another project to try and both keep my hand in the Perl world, as well as try and learn some new tricks, etc.
The below code is a small snippet of code which is called from a couple of different modules. However, it's not behaving the way I want or expect it to. Any chance you can point out where I'm going wrong please?
while (<DATA>)
{
chomp;
(@fields) = split(/\|/);
$cat_key = $fields[0];
$call_seq = $fields[1];
$copy_num = $fields[2];
$item_resctl = $fields[3];
$item_id = $fields[4];
$num_copies = $fields[5];
$call_holds = $fields[6];
$num_reserve_controls = $fields[7];
$bound_level = $fields[8];
$callnum = $fields[9];
$num_callnums = $fields[10];
$review = $fields[11];
$cat_acnt = $fields[12];
$status = $fields[13];
$copies_on_order = $fields[14];
$title_holds = $fields[15];
$title = $fields[16];
$discard = "YES";
# Added for debugging purposes
print("Item ID: " . $item_id . "\n");
# Trimmed additional checks and balances for brevity
if ($discard eq "YES")
{
# This is the problem child
printf("%d|%d|%d|%d|%d|%d|%s|\n",$cat_key,$call_seq,$item_id,$copy
+_num,$num_callnums,$num_copies,$title);
}
else
{
# This line works fine
print STDERR "$cat_key|$call_seq|$item_id|$copy_num|\n";
}
}
__DATA__
111|65|1|0|34211018032711 |1|0|0|NONE|CD ROC SYS|4|0|0|1|0|0|CD1|
611|38|1|0|34211012797211 |1|0|0|NONE|ANF 283.092 SPO|1|0|0|1|0|1|BOO
+K1|
1011|98|3|0|34211018090411 |4|0|0|NONE|P EDW|11|0|0|1|0|0|BOOK2|
1011|4|2|0|34211011193311 |1|0|0|NONE|ANF 070.43 WIL|1|0|0|1|0|0|BOOK
+3|
1211|12|1|0|34211014782811 |1|0|0|NONE|ANF 615.3257 MUR|1|0|0|1|0|0|B
+OOK4|
1212|87|1|0|34211017402911 |1|0|0|NONE|J BLY|6|0|0|1|0|0|BOOK5|
1711|82|1|0|34211016966711 |1|0|0|NONE|P WIL|3|0|0|1|0|0|BOOK6|
2111|5|1|0|34211002936811 |1|0|0|NONE|JNF 981.1 GHE|1|0|0|1|0|1|BOOK7
+|
2411|27|1|0|34211015588811 |1|0|0|NONE|JNF 597 HAR|2|0|0|1|0|0|BOOK8|
2711|34|1|0|34211016741111 |1|0|0|NONE|AF SAY|2|0|0|1|0|0|BOOK9|
This results in the output of :
Item ID: 34211018032711
111|65|-1|1|4|1|CD1|
Item ID: 34211012797211
611|38|-1|1|1|1|BOOK1|
Item ID: 34211018090411
1011|98|-1|3|11|4|BOOK2|
Item ID: 34211011193311
1011|4|-1|2|1|1|BOOK3|
Item ID: 34211014782811
1211|12|-1|1|1|1|BOOK4|
Item ID: 34211017402911
1212|87|-1|1|6|1|BOOK5|
Item ID: 34211016966711
1711|82|-1|1|3|1|BOOK6|
Item ID: 34211002936811
2111|5|-1|1|1|1|BOOK7|
Item ID: 34211015588811
2411|27|-1|1|2|1|BOOK8|
Item ID: 34211016741111
2711|34|-1|1|2|1|BOOK9|
So - why is it that $item_id appears to be being eaten by the printf line?? What have I done wrong? :)
EDIT: Hmmm... have done some more research on printf... thinking the issue could be that the number is too large to be interpreted as an Integer? If that's the case, any suggestions on how better to deal with it? Perhaps a string?