in reply to Darn Hash refs

What do you mean by "an error"? What "PRINTS HERE" but "DOESN'T WANT TO PRINT HERE"? Please read I know what I mean. Why don't you?. It's good that you've posted the code you've written, but without a clear description of your issue, we won't know how to attack the problem. Include printed errors, output, expected output, ...

Replies are listed 'Best First'.
Re^2: Darn Hash refs
by uni_j (Acolyte) on Apr 27, 2009 at 18:44 UTC
    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"; } }
      That start element you are processing doesn't have a "name" attribute, so $token->[2]{name} is undefined.
      Then shouldn't the compiler just skip over that line ? It's an if statement. I'm iterating through all the tags until one of them meets my conditions. I don't understand how this is bad code practice. I'm not able to know if a condition is met other wise. Why have if available to use in the first place right ?
        Who do you think you are responding to? ELISHEVA? You need to click the right reply link if you want to accomplish that, because you are responding to yourself :)