-
-
Notifications
You must be signed in to change notification settings - Fork 48
Open
Description
Hi @oalders
Just going through the codes for fun, I came across the sub _init_os() and noticed the use of index(). I think, we can make it more readable and maintainable. You can throw away the suggestion in the bin, if you don't like. I feel more comfortable discussing this with you. Hence raising the subject for your input.
My suggestion is to wrap the call to index() to something like is_matching($ua, @os_strings). What this will achieve? First it will clean up sub _init_os() and make it readable. Also less prone to any typo.
The new sub is_matching() would look like something:
sub is_matching {
my ($ua, $os_strings) = @_;
return 0 unless (defined $ua && scalar(@$os_strings));
foreach my $os_string (@$os_strings) {
return 1 if index($ua, $os_string) != -1;
}
return 0;
}
I haven't done any performance analysis yet, I must admit.
Best Regards,
Mohammad S Anwar
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels