3 ms·
Brings back memories of why I liked Perl so much back in the 90's. Nice work solving this. I'm curious about this bit: my $debitAmount = length(trim $field
by tyingq 4y ago
Brings back memories of why I liked Perl so much back in the 90's. Nice work solving this.
I'm curious about this bit:
my $debitAmount = length(trim $fields->[4]) > 0 ? trim($fields->[4]) + 0.0 : 0.0;
That patterns repeats itself a few times
It feels like you could safely shorten that down to:
$debitAmount=$fields->[4]+0;
Because the forced numeric conversion sort of does a trim on your behalf anyway, and "all spaces + zero" is zero.
- hnlmorg 4y agoThat or a printf/sprintf: https://www.tutorialspoint.com/perl/perl_printf.htm https://www.tutorialspoint.com/perl/perl_printf.htm
- hestefisk 4y agoThanks for the input! It is indeed a bit annoying I have to do that. Initially my code had what you suggested, but it caused a lot of "type casting" (in lack of a better Perl term) errors: Argument " " isn't numeric in addition (+) at lib/SGBankUtils/DBS.pm line 25, <$data> line 111. Do you know of a way of supressing / avoid this error? I want to keep warnings and strict on.
- tyingq 4y agoAh, it seems to be a warning, so it works, but is noisy. Something like what you're doing is needed then...I had thought space coercing to zero didn't do that.