how would I go about doing this? perl programming

Discussion in 'OT Technology' started by HardTech, Apr 19, 2007.

  1. HardTech

    HardTech hungry

    Joined:
    May 5, 2000
    Messages:
    28,103
    Likes Received:
    1
    Location:
    NorCal
    http://www.spock.com/do/pages/mini_challenges#wikipedia

    I want to apply to this company for a job and figured the best way would be to finish one of these programming challenges. However, this challenge is proving to be quite difficult as I have 0 prior experience with Perl.

    I've created an HTML page that simply has a text box and a submit button. It sends the text box contents (wikipedia link, either HTML or XML) to a script, which so far can only tell whether the link sent is HTML or XML.

    Here's my code:
    Code:
    wiki.cgi
    
    #!/usr/bin/perl -w
    	use LWP 5.64;
    	use CGI qw(:standard);
    	use XML;
    	use HTML::Form;
    	use HTML::Parser;
    	
    print "Content-type: text/html\n\n";
    
    #################################### #
    # get Wikipedia URL and retrieve webpage from Wikipedia #
    #################################### #
    my $cgi = new CGI;
    my $link = $cgi->param("wikipedia");
    
    my $browser = LWP::UserAgent->new;
    my $response = $browser->get( $link );
    	die "Can't get $link -- ", $response->status_line
    	unless $response->is_success;
    
    # determine the type of response; XML or HTML
    my $type = $response->content_type;
    my $content = $response->content;
    
    #my $isDump = false;
    #if ($type =~ /xml/i) { $isDump = true;  }
    
    # if xml
    #$xml = new XML::Simple;
    #$data = $xml->XMLin($content);
    #print $data;
    print "hello";
    
    # parse the contents
    #if ($content =~ m/birth(.*?)location/) {
    #	print "Hello $1";
    #}
    #print ($content=~ m/birth(.*?)location/);
    #print $content;
    #print "hello test 3!";
    
    as you can see, I've commented out a lot of code that doesn't work. I'm trying to parse the XML contents first before dealing with the HTML, but the parsing is VERY confusing :confused:

    any help?
     

Share This Page