Skip Menu |

This queue is for tickets about the Medical-NHSNumber CPAN distribution.

Report information
The Basics
Id: 73278
Status: resolved
Priority: 0/
Queue: Medical-NHSNumber

People
Owner: s.denaxas [...] gmail.com
Requestors: perl [...] toby.ink
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Try the following code: my $silly = '12345'; my @is_valid = Medical::NHSNumber::is_valid($silly); if (@is_valid) { print "$silly is valid!\n"; } It reports that the number is valid. This is because the is_valid function, when called in list context, returns a list containing one item (undef). Any list containing one item evaluates to true, not false. The code above is quite contrived, but there are situations when you can induce list context without really meaning to. The solution is quite simple: rather than returning undef, just return nothing. That is, replace things like this: return undef unless ( scalar(@digits) == 10 ); with things like this: return unless ( scalar(@digits) == 10 ); A bare "return" like that will always be treated as false whether called in scalar context or list context.
Thank you for the feedback. You are right, this is nasty habit of mine that I need to break. I've changed and pushed the code live - have a good xmas.
Added test and fixed in version .04