|There's more than one way to do things|
Alternative to smart matchby Bod (Curate)
|on Jan 22, 2022 at 00:22 UTC||Need Help??|
Bod has asked for the wisdom of the Perl Monks concerning the following question:
Happy January fellow Monks
I've written some code that works...but I don't like it!
Not only is it a bit messy, it also is probably not as efficient as it could be although it is only handle small amounts of data. But the main problem is that it uses Perl's smart match operator. I am using Perl 5.16.3 and smart match works well for what I want under this version. But I cannot guarantee it will always be using this version so don't want to stop it from being forward compatible.
Here's the bare bones of the code:
Essentially I am pulling data from a database. Collecting together a some information into the @authority array but I only want unique values. This strikes me as the sort of thing databases are good at so I could hit the database again with another query that's quantified as DISTINCT and build my @authority array from that. But that seems messy as well. In the vast majority of cases, @authority will only hold one value but there are few times when it will hold two, perhaps three.
I'm thinking grep or List::Util might be a more elegant and robust solution here.
Any suggestions would be very welcome...