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