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); }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: unexpected loop behaviour when pattern matching
by ikegami (Patriarch) on Dec 14, 2009 at 15:58 UTC | |
by jonnyfolk (Vicar) on Dec 14, 2009 at 16:13 UTC | |
Re: unexpected loop behaviour when pattern matching
by jethro (Monsignor) on Dec 14, 2009 at 16:00 UTC | |
by jonnyfolk (Vicar) on Dec 14, 2009 at 16:11 UTC | |
Re: unexpected loop behaviour when pattern matching
by Khen1950fx (Canon) on Dec 14, 2009 at 19:44 UTC |
Back to
Seekers of Perl Wisdom