I am trying to make a non-blocking request with
Mojo::UserAgent
but when I run the code below I get
Use of uninitialized value $_ in concatenation (.) or string
on the print
line.
How can I access $_
inside the callback?
my $ua = Mojo::UserAgent->new();
my @ids = qw( id1 id2 id3 );
foreach ( @ids ) {
my $res = $ua->get('http://my_site/rest/id/'.$_.'.json' => sub {
my ($ua, $res) = @_;
print "$_ => " . $res->result->json('/net/id/desc'), "\n";
});
}
Mojo::IOLoop->start unless Mojo::IOLoop->is_running;