in reply to Extracting information from hooks
my($webcrawler, $hook, $url, $response, $structure) = @_;I have the "Programming Perl" book and i have also looked around different tutorials but i can't understand how @_ works. Does it make something like:
$webcrawler = @_; $hook=@_; . . . $structure=@_;
No. @_ is an array (which contains the parameters passed to the function). When assigning to a list ((...)), the right hand side of the assignment is converted to a list (($_[0], $_[1], ...) in this case), the the first item in the RHS list is assigned the first item in the LHS list, the second item in the RHS list is assigned to the second item in the LHS list, etc. So,
($webcrawler, $hook, $url, $response, $structure) = @_;
is the same as
$webcrawler = $_[0]; $hook = $_[1]; $url = $_[2]; $response = $_[3]; $structure = $_[4];
In other words, it provides names for the arguments. (It has the side effect of making a copy of them.)
My problem now is that i can't understand how to store the content in a string.
The byte-for-byte response is available from $response->content(). Alternatively, you could traverse the HTML tree provided in $structure. Any of the dumping methods listed in HTML::Element would work. e.g. $structure->as_text().
|
|---|