I have some code I'm working with which had the assignment of a base PDF file in a giant 'if elsif' block. It was assigning a different base PDF for form filling using CAM::PDF based on what kind of form it was, and what state we were using. Let's say they were contracts, of two types, and there were two states, so the block went something like this:
if ($type eq 'A'){
if ($state eq 'GA'){
$form{source} = 'files/blanks/state/GA/A/contract.pdf';
}elsif($state eq 'TX'){
$form{source} = 'files/blanks/state/TX/A/contract.pdf';
}
elsif ($type eq 'B'){
if ($state eq 'GA'){
$form{source} = 'files/blanks/state/GA/B/contract.pdf';
}elsif($state eq 'TX'){
$form{source} = 'files/blanks/state/TX/B/contract.pdf';
}
}
This worked flawlessly, but it could be more elegant. I wanted this:
$form{source} = "files/blanks/state/$state/$type/contract.pdf";
I'm printing out the $form{source} value in a log, but if I reassign the value with the latter statement, though it looks identical to me in the log, the file doesn't open correctly. I have traced this through to line 384 in CAM::PDF (PDF.pm) where it tests for $self->_startdoc(). Even though the content loaded is identical, $self->_startdoc() returns undef if I assign the source via the simple assignment method and 1 if it was via the if/else method.