Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi there Monks!
A quick question for all; I am changing a web site to be mobile size ready and I am using Perl to generate the html, nothing fancy, but I am wondering if anybody here has done any browser(mobile) detection using Perl. I did some search(Google) and there is some stuff in PHP, but I rather stick with Perl if possible. Any suggestion will help me. I am trying to detect if the mobile browser is a windows phone, droid or iphone and have open a different CSS file for each different phone.
Thanks for any information!

Replies are listed 'Best First'.
Re: Detection of Browsers with Perl
by lostjimmy (Chaplain) on Feb 05, 2011 at 01:28 UTC
    Each HTTP request has a user agent string, which contains information about the browser and platform. For CGI scripts, this ends up in $ENV{HTTP_USER_AGENT}. You can try to match this against what you expect for Android/iPhone/Windows.

    Take a look at http://detectmobilebrowser.com which has detection scripts for many languages (sadly not Perl). You can study them and pull what you need out of their regexes.

    Also take a look at HTTP::BrowserDetect for general browser detection. It may come in handy.

Re: Detection of Browsers with Perl
by Anonymous Monk on Feb 05, 2011 at 01:30 UTC