in reply to Re: Bot vs human User Agent strings
in thread Bot vs human User Agent strings

Thanks...based on this solution and sleeping on it, I've implemented this solution:

open my $fh, '<', "....data/UserAgents/block.dat"; my @agent = <$fh>; close $fh; chomp @agent; my $invalid = grep { $ENV{'HTTP_USER_AGENT'} =~ /$_/i } @agent;

The solution from hippo has made me think, recall and investigate what Apache can do in this situation. However, I decided to do it this way instead of using Apache because it keeps all the logic in the method that processes the page headers. This is where the session cookie is set, so it makes sense (to me) to keep the code there as well. I feel this should be easy to maintain and easy to find.

I am a bit confused by a line in the above code:

if ($junk=~m/$badregex/) { print qq~\nSee....?\n~; }
Isn't the m operator redundant here or is it doing something subtle that I have overlooked?

Replies are listed 'Best First'.
Re^3: Bot vs human User Agent strings
by hippo (Archbishop) on Feb 11, 2024 at 00:02 UTC
    Isn't the m operator redundant here

    Yes, you are correct. However, it does no harm. It's not really an operator - rather it can serve to disambiguate the regex (for the compiler) in circumstances where it might not be clear. This is not one of those circumstances AFAICT.


    🦛