writch has asked for the wisdom of the Perl Monks concerning the following question:
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:
This worked flawlessly, but it could be more elegant. I wanted 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'; } }
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.$form{source} = "files/blanks/state/$state/$type/contract.pdf";
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: String assignment oddity
by syphilis (Archbishop) on Mar 01, 2018 at 22:28 UTC | |
Re: String assignment oddity
by Eily (Monsignor) on Mar 02, 2018 at 14:44 UTC | |
Re: String assignment oddity
by writch (Sexton) on Apr 17, 2018 at 15:19 UTC |
Back to
Seekers of Perl Wisdom