joyfedl has asked for the wisdom of the Perl Monks concerning the following question:

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;

Replies are listed 'Best First'.
Re: Running multi task
by kcott (Archbishop) on Aug 02, 2025 at 20:41 UTC

    G'day joyfedl,

    You seem to be thinking along correct lines. I didn't look too deeply at your detailed code. I think you probably want something like:

    $ perl -E ' my @lives = (1, 2, 3); my $url_base = "https://v3.football.api-sports.io/fixtures?live="; for my $live (@lives) { my $url = "$url_base$live"; say "Do stuff with $url"; } ' Do stuff with https://v3.football.api-sports.io/fixtures?live=1 Do stuff with https://v3.football.api-sports.io/fixtures?live=2 Do stuff with https://v3.football.api-sports.io/fixtures?live=3

    — Ken

      Thanks so much