Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

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); }

In reply to unexpected loop behaviour when pattern matching by jonnyfolk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and one hand claps...

    How do I use this? | Other CB clients
    Other Users?
    Others browsing the Monastery: (8)
    As of 2018-06-18 18:23 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      Should cpanminus be part of the standard Perl release?



      Results (110 votes). Check out past polls.

      Notices?