Skip to content

slight improvement to _init_os() #150

@manwar

Description

@manwar

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions