Non-blocking request $ua->get('mojolicious.org' => sub ($ua, $tx) { say $tx->result->dom->at('title')->text }); Mojo::IOLoop->start unless Mojo::IOLoop->is_running; |
$ua->get('mojolicious.org' => sub {my ($ua, $tx) = @_; say $tx->result->dom->at('title')->text }); |
my $wdir = "D:/blah"; for my $city ( keys %list ) { my $name = sprintf "%s/%s.json", $wdir, gbk($city); $query->{"toCountryId"} = $ct_code->{$city}; # 城市ID 更新到请求数据中 $res = $ua->post( $url, to_json( $query ), closure->( $name ) ); } $loop->start unless $loop->is_running; sub closure ($file) { return sub ($ua, $tx) { printf "%s\n", $file; write_file( $file, $tx->result->body ); } } |
use feature 'signatures'; no warnings 'experimental::signatures'; |
欢迎光临 批处理之家 (http://bbs.bathome.net/) | Powered by Discuz! 7.2 |