Grettings Monks;
When using two slightly different strategies
:one that involves passing the result of
a Form query into a sub and one outputing
the result immediately. Here's the code
and the results.
#! /usr/bin/perl
use LWP;
use HTTP::Request;
use HTTP::Response;
use HTML::Form;
$con=new LWP::UserAgent;
$con->agent('n3u7digit');
$request=new HTTP::Request(GET=>"http://www.<site>.org");
$reply=$con->request($request);
@forms=HTML::Form->parse($reply);
for $formh(@forms){@keys=keys %$formh;
for $name(@keys){
print "\t---$name\n";
}
}
....the second version ..
for $formh(@forms){@keys=values %$formh;
for $name(@keys){
process($name);
print "--$name--\n";
}
+ sub process{$return=shift;return $return;}
the output:
CASE 1
---enctype
---action
---method
---attr
---inputs
---enctype
---action
---method
---attr
---inputs
CASE 2
--application/x-www-form-urlencoded--
--http:/<site>.org/--
--GET--
--HASH(0x84d3d4c)--
--ARRAY(0x85190e4)--
--application/x-www-form-urlencoded--
--http://<site>.org/en/video?destination=node%xxxxxx--
--POST---
--HASH(0x852232c)--
--ARRAY(0x852ac40)--
So the utility of a closure seems evident, but why?
#! /usr/bin/perl
use LWP;
use HTTP::Request;
use HTTP::Response;
use HTML::Form;
$con=new LWP::UserAgent;
$con->agent('n3u7digit');
$request=new HTTP::Request(GET=>"http://www.<site>.org");
$reply=$con->request($request);
@forms=HTML::Form->parse($reply);
for $formh(@forms){@keys=values %$formh;
for $name(@keys){
process($name);
print "--$name--\n";
}
sub process{
$return=shift;
return $return;
}