Right now I am getting this error... Use of uninitialized value in string eq at UOT_mississauga.pl line 40. I'm looking on google and here but I'm not sure how this error is happening. How would I work around this. How can token be uninitialized ?
use strict; use warnings; use WWW::Mechanize; use HTML::TokeParser; use Data::Dumper; my $pre = ''; my $html; my $htmll; my $htmlll; my $term = 20095; # 20095 = Summer; my $year = 1 ;# 1st = 1 , 2nd = 2, 3rd = 3, 4th = 4 my $key; my $v; my $coursecode; my $department; my $prepre; my $id; my $stuff; my $title; my $description; my $course_num; my $check; 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 %newdep; my @coursename; my @c_arr ;# Course array $mech->get($url); $html = $mech->content(); $stream->get_tag("option"); while(my $token = $stream->get_token()){ if($token->[0] eq "S" && $token->[2]{name} eq "dept/[/]"){ print Dumper $token; while(my $token = $stream->get_token()){ if($token->[1] eq "option"){ $course_num = $token->[2]{value}; $department = $stream->get_trimmed_text(); $dep{ $course_num } = [$department]; } } } } while (($key, $v) = each(%dep)){ $coursecode = $key; $coursecode =~ s/\s//g; $department = $v; $mech->get($url); $mech->submit_form( fields=>{ session=>$term, 'yos[]'=>$year, 'dept[]'=>$key, }, ); $htmll = $mech->content(); ### PRINTS HERE while(my $tokenn = $streamm->get_token()){ ### DOESNT WANT TO PRINT HERE if($tokenn->[1] eq "a" && $tokenn->[2]{name}){ push(@coursename,$tokenn->[2]{name}); $prepre = $tokenn->[2]{name}; $newdep{ $department } = $coursecode; } } } while (($id, $stuff) = each(%newdep)){ print "Id:$id Stuff:$stuff .\n "; } sub print_csv{ foreach(@coursename){ $pre = $_; print $pre; $mech->get($c_url); $htmlll = $mech->content(); $streammm->get_tag("p"); $title = $streammm->get_trimmed_text(); $title =~ s/($coursecode).//g; $streammm->get_tag("/p"); $description = $streammm->get_trimmed_text(); #print '"'.$prefix.'";"'.$title.'";"'.$description.'";"'.$departme +nt.'"'."\n"; } }

In reply to Re^2: Darn Hash refs by uni_j
in thread Darn Hash refs 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.