http://qs321.pair.com?node_id=1108140


in reply to Asynchronous HTTP requests

It's in the header...

use AnyEvent::Loop; use AnyEvent::HTTP; http_get 'http://yahoo.com', sub { my ($body, $hdr) = @_; die $hdr->{U +RL} }; AnyEvent::Loop::run;

And if it wasn't, or there is other information you'd like to use.. capture it as a closure when the sub is defined.. for instance:

use AnyEvent::Loop; use AnyEvent::HTTP; use feature 'say'; for my $url ('yahoo.com', 'google.com') { http_get "http://$url", sub { say STDERR $url }; } AnyEvent::Loop::run;

Two separate callback subs are created, and in each of them $url will be set to the value it held when the http_get was run.