http://www.perlmonks.org?node_id=812720
jonnyfolk has asked for the wisdom of the Perl Monks concerning the following question:

Further to my previous post on XML::Simple I am using the advice of the good monks to loop through the user_agent field.

foreach my $browser ( values %{$data->{devices}->{device}} ) { my $useragent = lc($browser->{user_agent}); my $userfb = lc($browser->{fall_back}); print Dumper(\$useragent, \$userfb, \$user); }

However adding a pattern match to the loop reduces the results to a mere couple and I really don't understand why! Can anyone enlighten me as to why this is affecting the behaviour of the loop and how I can phrase the statements so that the loop runs through all the listed user agents, while comparing the http_user_agent?

#!/usr/bin/perl -w use strict; print "Content-type: text/html\n\n"; # use module use XML::Simple; use Data::Dumper; use LWP::Simple; my $url = 'http://wurfl.sourceforge.net/web_browsers_patch.xml'; my $user = $ENV{'HTTP_USER_AGENT'}; $user = lc($user); my $content = get($url); # create object my $xml = new XML::Simple; # read XML file my $data = $xml->XMLin($content); # print output my @agents; my $check; foreach my $browser ( values %{$data->{devices}->{device}} ) { my $useragent = lc($browser->{user_agent}); my $userfb = lc($browser->{fall_back}); $user =~ /$useragent/; print Dumper(\$useragent, \$userfb, \$user); }