I have a question I'm hoping you could help with?
foreach my $url ( keys %{$newURLs} ) {
# first get the base URL and save its content length
$mech->get($url);
my $content_length = $mech->response->header('Content-Length');
# now iterate all the 'child' URLs
foreach my $child_url ( @{ $newURLs->{$url} } ) {
# get the content
$mech->get($child_url);
# compare
if ( $mech->response->header('Content-Length') != $content_length ) {
print "$child_url: different content length: $content_length vs "
. $mech->response->header('Content-Length') . "!\n";
#HERE I want to store the urls that are found to have different content
#lengths to the base url
#only if the same url has not already been stored
} elsif ( $mech->response->header('Content-Length') == $content_length ) {
print "Content lengths are the same\n";
#HERE I want to store the urls that are found to have the same content
#length as the base url
#only if the same url has not already been stored
}
}
}
The problem I am having:
As you can see in the code above I want to store the urls depending on if the content lengths are the same or different, so I will end up with a group of urls that had a different content length to their base url and I will end up with another group of urls that had the same content length to their base url.
I know how to do this easily using an array
push (@differentContentLength, $url);
push (@sameContentLength, $url);
But how would I go about this using a hash (or another preferred method)?
I am still getting to grips with hashes so your help will be much appreciated,
thanks a lot