Hey guys, My code (a web scraper) is designed to grab the information from a website site. Everything is good, but my main problem has to do with my last hash ("%dep2"). It is suppose to have a lot of data because in my "%dep" hash loop(without the '2'). Also, if anyone wants to show me how to keep reusing the same $stream, I'm sure that would clean up my code a bit ;)
use WWW::Mechanize; use HTML::TokeParser; my $c_url = 'https://registrar.utm.utoronto.ca/student/timetable/new_t +t_calprev.php?course='.$pre; my $url = 'https://registrar.utm.utoronto.ca/student/timetable/index.p +hp'; my $mech = WWW::Mechanize->new(); my $stream = HTML::TokeParser->new(\$html); my $streamm = HTML::TokeParser->new(\$htmll); my $streammm = HTML::TokeParser->new(\$htmlll); my %dep; my %dep2; my @coursename; $mech->get($url); $html = $mech->content(); $stream->get_tag("option"); $term = 20095; # 20095 = Summer $year = 1 ;# 1st = 1 , 2nd = 2, 3rd = 3, 4th = 4 my @c_arr ;# Course array while(my $token = $stream->get_token()){ if($token->[2]{name} eq "dept[]"){ while(my $token = $stream->get_token("option")){ if($token->[1] eq "option"){ $c = $token->[2]{value}; $d = $stream->get_trimmed_text(); $dep{ $c } = $d; } } } } while (($key, $v) = each(%dep)){ + #submit options to list course $coursecode = $key; $coursecode =~ s/\s//g; $mech->get($url); $mech->submit_form( fields=>{ session=>$term, 'yos[]'=>$year, 'dept[]'=>$key, }, ); $htmll = $mech->content(); while(my $tokenn = $streamm->get_token()){ + #grab the prefixes from the listing so we can directly if($tokenn->[1] eq "a" && $tokenn->[2]{name}){ push(@coursename,$tokenn->[2]{name}); $c = $tokenn->[2]{name}; $dep2 { $key } = $c; } } + #end while for prefix } while (($foo, $bar) = each(%dep2)) { print $foo; print $bar; }

In reply to Hash loop debugging. by uni_j

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, details, 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, summary, 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.