hi...

i have the following code, that seems to be giving me an issue... i've tried
running the code on both linux/windows and get the same results...
 so i've screwed something up.. but i can't figure out what...

basic overview:
i have two hash arrays that i create, and i iterate through the arrays using
two foreach loops, one inside the other... within the inner most loop, i
call a sub/routine that builds a URL and attempts to download a web page..
pretty simple stuff...

symptoms..
the issue i'm seeing is that i'm not able to pass one of the hash vars into
the "get1" function. in fact, there is a line within the function that
appears to be overwriting memory, or some other issue. when i comment out
the line in question, the var that i'm looking to pass into the sub/function
is able to be created, and passed as expected.

the weird behavior is that the var in question "semester_key" in the main
section, apparently is not present when i call the "get1" sub, as i don't
even see it when i attempt to print out the vars directly before calling the
"get1" sub...

currently, i'm pretty stumped... i'm willing to bet that i have a
simple/subtle mistake, but i can't seem to find it... i've rewritten the
app/functions a number of time, thinking that i may have a typo somewhere,
or some other screwup...

any help/comments will be appreciated...

thanks...

-bruce

sample code
#############################################################
#
# uminnesota.pl. test perl app to extract/parse class
#       schedule from the onestop2.umn.edu registrar site...
#
#
# todo.. need to create the getinfo routine to parse the
#        class information, and write it out
#
#############################################################
#!/usr/bin/perl -w

use HTML::TreeBuilder;
use LWP::UserAgent;
use URI::Escape;

   $ua = new LWP::UserAgent;

   $ua->timeout(30);
   $ua->agent("Mozilla/4.0 (compatible; MSIE 4.01; Windows95)" .
$ua->agent);

#
# get the top level university class site
#
  my $base_url =
"http://onestop2.umn.edu/courseinfo/classschedule_selectsubject.jsp?institut
ion=UMNTC";

  my $base_search_url =
"http://onestop2.umn.edu/courseinfo/viewClassScheduleTermAndSubject.do";;


# get semesters
my (%s1) = &getsemesters($base_url);

# get depts
my (%d1) = &getdepts($base_url);

my $semester_key;
my $dept_key;

foreach $semester_key (keys(%s1))
{
     foreach $dept_key (keys(%d1))
     {
       print " sem_key = $semester_key   deptkey  $dept_key\n";
       &g1($base_search_url, $semester_key, $dept_key);
     }
}

print "we're here...\n";
die;



#################################
#
#
#################################
sub getsemesters
{
   my ($url) = @_;
   my (%semester);

   my $req = new HTTP::Request GET => $url;

   $req->content_type('application/x-www-form-urlencoded');

   my $res = $ua->request($req);
   my $q1c = $res->content;

   my $_tree = HTML::TreeBuilder->new_from_content($res->content); # tree

   # get the specific select
   my @_sel = $_tree->look_down("_tag"=>"select", "name"=>"searchTerm");

   #get the option/semester list
   my @_option = $_sel[0]->look_down("_tag"=>"option");
   foreach $a (@_option)
   {
      $semester{$a->attr('value')} = $a->as_text();
  }

   return(%semester);
}


#
# return the hash containing the dept list
#
#   if necessary, might need to also provide the
#   short name for the dept..
#
sub getdepts
{
   my ($url) = @_;
   my (%depts_);

   my $req = new HTTP::Request GET => $url;

   $req->content_type('application/x-www-form-urlencoded');

   my $res = $ua->request($req);
   my $q1c = $res->content;

   my $_tree = HTML::TreeBuilder->new_from_content($res->content); # tree

   # get the specific select
   my @_sel = $_tree->look_down("_tag"=>"select", "name"=>"searchSubject");

   #get the option/semester list
   my @_option = $_sel[0]->look_down("_tag"=>"option");
   foreach $a (@_option)
   {
      $depts_{$a->attr('value')} = $a->as_text();
   }

   return(%depts_);
}

sub g1
{
  my ($url, $semester_, $dept);
  ($url, $semester_, $dept)  = @_;

my $url1;

  print "here  $url $semester_  $dept \n";

$institution = "?institution=UMNTC";
$searchterm = "&searchTerm=";
$searchsubject = "&searchSubject=";
$q_string = "&searchFullYearEnrollmentOnly=false&Submit=View";

$url1 = $url;
$url1 = $url1 . $institution;
$url1 = $url1 . $searchterm. uri_escape($semester_);
$url1 = $url1 . $searchsubject. uri_escape($dept);
$url1 = $url1 . $q_string;


   my $ua1 = new LWP::UserAgent;

   #$ua->timeout(30);
   #$ua->agent("Mozilla/4.0 (compatible; MSIE 4.01; Windows95)" .
$ua->agent);

   my $req_ = new HTTP::Request GET => $url1;

   $req_->content_type('application/x-www-form-urlencoded');

   my $res1 = $ua1->request($req_);
   #my $q1c = $res->content;
   #print $q1c;
print "url = $url1\n";

}

by commenting out the " my $res1 = $ua1->request($req_);" line, i can get
the print statement prior to the "&get1" function to print out all the vars.
with the line included, the "semester_key" var is not printed...



Reply via email to