[TriLUG] Help: Web form filler app?

Jonathan Rippy jonathan.rippy at interpath.net
Fri Jan 11 16:25:59 EST 2002


This should allow you to do what you want to do.
I even commented it for ya.  :)  Whipped it up in
about 5 mins... perl rules! :)

This example will read a file called "values.tsv" in TAB 
seperated form and post the values to the CPAN search page.  
Create the file with a line like 'module\tLWP::UserAgent' 
and it will search for the module LWP::UserAgent on the CPAN 
archive.  The comments+code should explain everything.

Enjoy...

#!/usr/bin/perl
require LWP::UserAgent;

# Create new new LWP::UserAgent object
my $ua = LWP::UserAgent->new();

# Open up the file which contains our values in TAB seperated form
#   Namely, module\tLWP::UserAgent
open(FILE, "values.tsv");

# Iterate through the file
while(<FILE>) {
    chop;       # remove the trailing \n from the magic variable $_
    $line = $_; # magic variable that contains the current line (in this case)

    # split the line based on tabs into the variables $mode and $query
    ($mode, $query) = split ( /\t/, $_ );

    # assign them to our formValues hashtable
    $formValues{"mode"} = $mode;
    $formValues{"query"} = $query;

    # Invoke a post to the ACTION of the form found on search.cpan.org
    my $response = $ua->post('http://search.cpan.org/search', \%formValues);
    if ($response->is_success) {
        # Print the content to STDOUT if succesfull
        print $response->content;
    } else {
        # Print the error 
        print $response->error_as_HTML;
    }
}
close(FILE);

-- 
jonathan rippy



More information about the TriLUG mailing list