Skip to content

Instantly share code, notes, and snippets.

@HakimCassimallyBBC
Created September 16, 2016 09:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HakimCassimallyBBC/f69ee16d01ec5db7f76781b5c1bba29a to your computer and use it in GitHub Desktop.
Save HakimCassimallyBBC/f69ee16d01ec5db7f76781b5c1bba29a to your computer and use it in GitHub Desktop.
multicurl in Perl
use strict;
use warnings;
use IO::Select;
my %handle_names;
my $s = IO::Select->new;
for my $url (@ARGV) {
open (my $handle, '-|', 'curl', '-s', '-k', $url);
$s->add($handle);
$handle_names{$handle} = $url;
}
my $current_handle = 0;
while ($s->count) {
my @handles = $s->can_read(0.25);
for my $handle (@handles) {
printf "\n==> %s <==\n", $handle_names{$handle}
unless $current_handle == $handle;
$current_handle = $handle;
print scalar <$handle>;
if (eof $handle) {
print "*** URL closed ***\n";
$s->remove($handle);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment