Use of uninitialized value in string eq at UOT_mississauga.pl line 40

If the line 40 in your posted code is the same as the line 40 in your script, that means that the marked line below is the source of the problem.

my @coursename; my @c_arr ;# Course array $mech->get($url); $html = $mech->content(); $stream->get_tag("option"); while(my $token = $stream->get_token()){ my $check = $token->[2]{name}; if($check eq "dept[]"){ while(my $token = $stream->get_token('option')){ #### THE LINE BELOW TRIGGERED THE FOLLOWING MSG #### #### Use of uninitialized value in string eq #### if($token->[1] eq "option"){ $course_num = $token->[2]{value}; $department = $stream->get_trimmed_text(); $dep{ $course_num } = [$department]; } } } }

If I have the right line, my guess is that the value of $token->[1] is undefined. To verify that $token->[1] (or any other variable you might care about) is undefined, you can insert code similar to the following code snippet.

# value surrounded with < > to make it easier to see # empty strings print STDERR "token[1]=<" . (defined($token->[1]) ? $token->[1] : 'undef') . ">\n";

In future posts, please mark the exact line mentioned in the error message along with the error message as I have done above. We have no way of knowing whether the line numbers of the posted code match the line numbers of your script and will be playing guessing games about where your error might be unless you mark it for us.

Best, beth


In reply to Re: Darn Hash refs by ELISHEVA
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.