I have a sample data, my question is that what is the best way to run multi-task, the URL API Endpoint is the one which is different but the tasks are the same like
my $url = "https://v3.football.api-sports.io/fixtures?live=1"; my $url = "https://v3.football.api-sports.io/fixtures?live=2"; my $url = "https://v3.football.api-sports.io/fixtures?live=3";
i was thinking on that this could work after code block i put continue Loop then other code block
my problem is that i don't want to make multiple files which does same work, i want to include them in same file and run once
#!/usr/bin/perl -wT use strict; use warnings; use LWP::UserAgent; use HTTP::Request; use JSON; use DBI; my $host = ""; my $usr = ""; my $pwd = ""; my $dbname = ""; my $dbh = DBI->connect("DBI:mysql:$dbname:$host", $usr, $pwd, { AutoCommit => 1, RaiseError => 1, }) or die $DBI::errstr; my $url = "https://v3.football.api-sports.io/fixtures?live=1"; my $ua = LWP::UserAgent->new; my $req = HTTP::Request->new(GET => $url); $req->header('x-rapidapi-host' => 'v3.football.api-sports.io'); $req->header('x-rapidapi-key' => 'e73299760f882d'); my $response = $ua->request($req); my $parse_json = JSON::XS->new->decode ($response->content); if ($response->is_success) { for my $match (@{$parse_json->{response}}) { my $elapsed = $match->{fixture}{status}{elapsed}; my $status = $match->{fixture}{status}{short}; my $home = $match->{teams}{home}{name}; my $away = $match->{teams}{away}{name}; my $ht_home = $match->{score}{halftime}{home} // 'N/A'; my $ht_away = $match->{score}{halftime}{away} // 'N/A'; my $ft_home = $match->{score}{fulltime}{home} // 'N/A'; my $ft_away = $match->{score}{fulltime}{away} // 'N/A'; my $query = $dbh->prepare("# MYSQL QUERY"); $query->execute(); my $query_data = $query->fetchrow_array; $query->finish; # more select below............. if (int($elapsed > 0)) { my $Create = $dbh->prepare("# MYSQL QUERY) VALUES()"); $Create->execute(); $Create->finish(); } # more insert below............. } } else { print $response->status_line; } $dbh->commit; $dbh->disconnect;
In reply to Running multi task by joyfedl
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |