in reply to ENV variable

$ENV{HTTP_USER_AGENT} is only set by your webserver when it runs your script (as a CGI script). It is not set in your shell, because there is no browser connected to your shell session. How did you check the contents of %ENV, and in what environment?

Replies are listed 'Best First'.
Re^2: ENV variable
by irah (Pilgrim) on Feb 02, 2009 at 08:01 UTC
    My program follows, sub is_firefox { my $agent = ''; $agent = $ENV{"HTTP_USER_AGENT"} || ''; if (length($agent) && $agent =~ m/firefox/si) { return 1; } return 0; } I have printed all the keys and values of %ENV using while and each. I have checked this in Debian Linux, and Apache server.

      It's quite possible that your browser does not send its user agent.

      Also, what code you've shown is not a complete program, hence I cannot tell whether there is some other error. You should consider starting using CGI or CGI::Mini, which have the ->user_agent() method, which caters for other ways of passing the user agent around. For example, mod_perl likely doesn't set $ENV{HTTP_USER_AGENT}, because %ENV is process global and mod_perl can run in system threads.