Skip Menu |

This queue is for tickets about the Lingua-EN-NameParse CPAN distribution.

Report information
The Basics
Id: 85491
Status: resolved
Worked: 20 min
Priority: 0/
Queue: Lingua-EN-NameParse

People
Owner: kimryan [...] cpan.org
Requestors: ovid [...] cpan.org
Cc:
AdminCc:

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



Subject: Don't return undef
Hi there, Thanks for the useful module. Methods such as case_components return a hash or undef. However, that leads to this problem: my %components = $name_parse->case_components; And that either works or, if we get an undef, results in: Odd number of elements in hash assignment at If you use a bare return statement: return; # not: return (undef); Then this warning goes away. Sadly, our current code is sprinkled with "no warnings" statements to avoid this issue. Cheers, Ovid
Hi Ovid, thanks for alerting me to this. I had a look through the Changes file and found this entry for version 1.23 --------------- components method now returns undef if name cannot be parsed. Thanks to Patrick Kane. --------------- Can't remember why this request was made. My thoughts are it is better not to use a common variable to denote both data and error status. I would suggest adding an error flag to the returned parameters. If the parsed name has no components, an empty hash will be returned and an error flag set to 1. Otherwise, return a hash with some values and error flag is 0. This way, the module is also backwards compatible, if you don't account for the new second parameter. (%name_comps,$error_flag) = $name->components; unless ($error_flag) { # (%name_comps has some key/value pairs ... } Regards, Kim
Now only using return statement, not return(undef)