my %pi; my ($status, $content, $type, $base, $length) = get_page(\$site, \%pi); print $pi{'length'}, " bytes\n"; #################################################### sub get_page { my ($site_ref, $pi) = @_; $browser = LWP::UserAgent->new() unless $browser; my $response = $browser->get($$site_ref); my $status = $response->status_line; my $content = $response->content; my $type = $response->content_type; my $base = $response->base; my $length = commify(length($content)); if (!$response->is_success) { die "\nError: $status ($site)\n"; } @{$pi}{qw(status content type base length)} = ($status, $content, $type, $base, $length); }
It may not be the most-efficient, because I'm still trying to wrap my head around references and anonymous references to subs, but it does work for me.
Comments or improvements are welcome, as long as they provide the fishing pole and a lure, not a basket of fish..
In reply to Re: Optimizing the use of hashes in subroutines
by hacker
in thread Optimizing the use of hashes in subroutines
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |