There are many problems with this code, but here are your biggies:
- Don't construct your query string by hand. The POST method of HTTP::Request::Common does this for you. You simply supply it with an anonymous array in the form of [username=>$username, password=>$password, ...].
- If you do the above, you will not need your substitution statement.
- The || operator is a high-precedence operator. See perlop for the details, but in short, the || in the "fail 1" line evaluates before the comma operator does. In fact, the only reason your code does not print "fail 1" is because || short-circuits on the "true" evaluation of $formurl.
- In general, what you're trying to do is actually much easier than you are making it out to be. Here is one way it can be done:
use LWP::UserAgent;
use HTTP::Request::Common;
my $formurl = "http://www.amihotornot.com/board.pl";
my $id = 20010131;
my $username = "MeowChow";
my $password = "catfood";
my $subject = "Fancy Feast is neither fancy nor a feast.";
my $post = "Discuss amongst yourselves...";
# construct an anonymous array for the Http::Request::Common::POST met
+hod
my $formvars = [
id => $id,
username => $username,
password => $password.
subject => $subject,
comments => $post,
submit => "Submit",
];
$ua = new LWP::UserAgent;
$ua->request(POST $formurl, $formvars);
- Read the HTTP::Request::Common documentation, specifically the part about POST.
MeowChow
print $/='"',(`$^X\144oc $^X\146aq1`)[-2]